Apple'E
ATouch of Applesoft BASIC
Apple ilc, Apple Jle, Apple liGS'"
A. Apple JI A Touch of Applesoft BASIC
it APPLE COMPUTER, INC_
© Copyright 1986, Apple
Computer, Int., for all non-
lexlual material, graphics,
figures, pliDCograph.'j, antl all
compuLcr program listings or
code in any form, including
object and source code, All
rights reserved.
Apple and ihe Apple logo are
registered tmdcmarks of Apple
Computer, Inc.
Macintosh is a uademark of
Mcintosh Lahnratories, Inc.,
and is being used wilh express
permission of its owner,
Microsoft is a registered trade-
mark of Microsofi Corporation.
POSTSCRIPT is a U-ademark of
Adobe Systems Incorporated.
ITC Garamond, ITC Avant
Garde Gothic, and ITC Zapf
Dingbats are registered
trademarks of International
Typeface Corporation.
Printed in Singapotie.
Contents
Preface vii
Whal's a computer language? vii
WhaL's a program? viii
Do you have lo program? viii
Why would you want lo learn lo program? viii
Patience required ix
1 low to get started ix
And now — begin! x
Session 1 Gettir\g S^□^ted 1
The elemeniary stuff 2
Editing: program first aid 4
Summary and review 5
Sessiorv 7 Arithmetic and Voriabies 7
Arithmetic 8
Precedence: the order of calculations 10
Use parentheses to change precedence 10
Variables 1 1
Naming variables 13
Break a few rules 14
Summary and review 15
Content? H
Session 3 The Ourslde World 17
INPUT 18
Prompts 19
More ediling: adding lines 20
Cleaning up with HOME 20
LIST 21
String variables 22
Variables rules recap 23
Debugging 23
Summary and review 25
Session 4 Using the Disk and Other Devices 27
Computer memory 28
Files and catalogs 29
How to save prograjns 29
Reading Ehc catatag and retrieving a program 31
Cleaning up 32
For printer owners: printing your listings 33
Using what ycHj've learned
Summary and review 3^
Se&Sion 5 Loops and Condilions 35
Loops 36
GOTO 36
Conditional branching wiih IF.. .THEN 37
Building on the model 3S
Relational operators 38
Use RFiM for remarks 41
Practice lime 4l
Summary and review 42
Iv Contents
session 6 Graphics 43
Text and graphics 44
A '!0-b>MO canvas 45
Seeing your listing again A6
Floaing colors wilh COLOR=
Using variables far ploiting and coloring 47
Incrcmeming columns and raws 48
Drawing horizontal and vertical lines 48
A universal line-drawer ^9
Random graphics 50
Summary and review 52
Seuion 7 conirolled Loops 53
FOR V NEXT 54
UsLng STEP wilh FORVNEXT 56
Delay luops 57
A quick review 59
Expcrimcni before you continue 6o
Summary and review 60
Session 8 Programming With Style: Modular Programming 61
GOSUB\ RETURN 62
ENT) proiecis subrouiincs 63
Subroulines and organizaiion 64
Multiple inslruclions on one line 6S
Organizing your programs; one siep at a lime 66
The greai checkbook balancing program challenge 67
One veraion of a checkbook balancing prograni 67
Summary and review 68
Cor^t&nts V
Session 9 Formatting Scjreenj 69
Horizontal and verticaJ tabs 70
Prompt placement 73
Celling noticed: 1^4VERSK and NORMAL 74
A text-centering atgorithm 75
One solution lo the centering problem 75
Sumniaiy and review 76
Session 10 Pfogramming toi People 77
A Sordid history 78
People-program guidelines 79
Humanizing programs isn't easy 81
It gets easier 81
Where do you go from here? 81
Do it! 82
A parting word 83
Appendix A A Summary ol Applesoft Instructions B5
Appendix B Reserved Words 99
Glossory 101
Index 107
Contents
Preface
This tutorial will hc!p you get started writing simple Applesoft BASrC computer
programs on your Apple^ ll computef. You won't learn all ihcre is 10 know about
Applesoft BASIC from just this tutorial; but by the time you Pinish these ten sessions,
you'll be able to decide whether you want to continue learning about programming.
'itie product training disk that came wiih your computer gives you a brief introduction
to Applcsoftj you might want to work with that disk before you read ihis tutorial.
What's a computer language?
A computer language is like the languages that people speak. U has a vocabulary and
a syntax — word order is important and Spelling counts. Your Apple computer sp>cak5
a language called Applesoft BASIC (It .speaks other languages, loo, but ihcy aren't
built into the computer; you buy them on disks.) The computer reads ihe Bj\SIC
instructions you type from the keyboard, and ihen it docs exactly what it's told.
Luckily, it's easier to learn BASIC than a human language because BASIC has far fewer
words, and its grammar is usually very straightforward.
IMS^C fjy any other name There are many variations on the BASIC computer
language. But in this litde tutorial the terms BASIC, Applesoft BASfC, and
Applesoft all refer to the same thing.
What's a computer language?
What's a program?
Computer programming is writing inslruclions for your computer. The entire sci of
insLruoions you give lo a computer to make it do something is the program. Imagine
that your compuicr is a pet you want to train. You canl talk to your pet in the same
way you talk wiih a human; you have lo use a limilcd vocabulary to IcU it exactly what
to do. If you wanted it to do a series of things, you would give it a set of insUucUons,
one iasirucLion at a time. For instance, suppose you want your pet to sit, lie down, '
and roll over. You'd do it like this:
"King, sit."
(King sits.)
"King, lie down."
(King lies down.)
"King, roll over."
(King rolls over,)
"Good dog!"
(King wags tail.)
Of course your Apple won t sit, lie down, or roll over, but it will do a lot of things for
you if you give it instructions in a syslemaUc and logical order. You use the .same kind
of directness, simplicity, and order in computer programming as in pet training
(except lhat you don't have to praise your computer when it docs what you icU it).
Do you hove to program?
You don^i have to write programs to use your computer. Thousands of programs
have already been written for your Apple— programs for word processing, financial
analysis, computerised Tite cabinets, and dozens of other applications. You just pul
a disk with programs on it into your disk drive and turn on your computer.
Why would you want to learn to program?
Firsi of all, you might Hnd programming lo be a lot of fun. -ftTicn you learn to
program, you discover ihat your Apple isn't really magical (although it certainly
seems that way at times); it's jusi following the instmctions that you give i[. When you
program your computer, you make it do what you want it to do— you ge( LO create your
own magic. Second, you learn a lot about how a computer works as you learn to
vlii Preface
program iL That gives you a better understanding of whit your computer can and
can't do. Finally, you might find that programming is something that really intrigues
you and stimulates your own creativity in ways you'd never thought about, You might
eventually decide to become a professional programmer.
You can create simple entertainment, educational, and business programs wiih just
an elementary set of instructions. For example, you can write very efTeetive
educational games in Applesoft BASIC, or even home budgeting and checkbook
programs lo keep your finances in order.
Writing your own program is an option available on your Apple. While you're likely
EG find programming useful and interesting, you don't have to learn how to program
to use your computer. But if you do want to program, you'll find Applesoft BASIC a
great place to start
Patience required
Learning to program is a little like learning how to become a chef. You've got to be an
experienced chef to pull off great seven-course meals; but the essentials of the craft
begin with melting butter, mrning an egg, and so on. And the payoff is similar, too.
You don't have lo be a master chef to enjoy a homemade omeleue (or ama3^ your
friends with your culinary prowess).
From time to lime, you'll just have to be patient — but only for a little while. Have
faith.
How to get started
Applesoft is built irttoyour Apple II computer. But you need to prepare your
compuler to Store the programs you create so that you can use Ihem again. (You'll
leim more about storing your programs onto disk in Session 4.) Here are the steps to
take to begin your smdy of Applesoft BASIC:
1. Read your Apple computer owner's guide Pirst. It contains lots of valuable
information aboul the computer that you'll need to know before you can begin to
use Applesoft. Pay af>ceial attention to the section on formatting disks. You'll
need at least one formatted disk before you can start.
2. Insert the utilities di.5k that came with your computer into the disk drive, dose the
dusk drive door, and turn on the computer. (See your owner's manual for
instructions ) Choose the Applesoft UASlC option and press Return; you should
see this symbol: ].
3. Remove the disk from the drive and replace it with a formatted disk. Be sure lo
Close the drive door.
How to get started be
^ UsiTTg Applesoft without a disk drivs: if you don't have a disk drive, you can sUU
write programs; but you won'i be able lo slorc Lhcm. To start BASIC witljoui a disk
drive, turn on your computer and then press the Control and Reset keys at the
same time, then release them. You'll see ihis symbol; ].
And now— begin!
This tutorial is divided into ten sessions- youll need about an hour for each session.
Be sure to spend lots of time practicing what you've learned in each session befoire
going on to the next one; each session builds on the previous one.
Above 3]!, have a good time. Exfjeriment as much as you can. Break the mlcs. Try
crazy thing.^ — Uie worst thing that can happen is that the computer will beep at you.
(When this hap[X:ns, beep back.)
Now^ all you have to do is turn the page and begin,
X Preface
Session 1
Getting Started
The best way lo find out If you like programming is to do some. To keep
things simple, do everything cxacUy as it's presented in this tutorial. Of
course if you get bored, strike out on your own! You won't break the
computer by typing something wrong, and the important thing is to
experiment, learn, and have fun.
In this first session, you 11 learn the rudiments. You'll read about program
Macs and line numbers, and how to type in programs. Vou'H sec how to
put messages on the screen with the PRINT instruction, and you'll learn
some things about programming mistakes and how lo fix them.
The elementary stuff
Before you do anything else, type the word new and press the Return key.
NEW tells your Apple compticer Lo make way for a new program. Pressing
Return tcils your Apple to look at what you just typed. Umil you press
Return, your Apple thinks you're jusi talking to yourself:
Press Return here.
Now type the following line exactly as you see it, and then press Return:
iQ PSiHT "SIT- = Press Return hore.
The number 10 is called a line number Your Apple executes the lines of
instructions you type in numeric order, always beginning with the lowest
number. For the time being, number your program lines by lO's. You'll
learn why later in Session 3-
After you've typed all the instructions (which youVe jusl done — your first
program is a short one), type run and press Return. The RUN command
tells your Apple thai you've finished giving it instructions and that you want
it to carry them out:
' " ~ Press Ratuin here.
Your video display should look something like this:
IKEW
] 10 PRINT "STT"
131T
2 Getting Started
You've jusi written and executed (another word for run) your first computer
prosram. Congratulations! You ve also just learned one of the most often
used programming instructions: PRINT. The PlilNT in.struaion tells your
computer lo display whatever appears within quotation marks, llere's
some more practice u.?irig PRINT. Type the following program exactly as it
appears. (If you make a mistake, just press Return and retype the line.) Be
sure lo press Return ai the end of each line;
10 prirtt "lie down"
20 Prifif: "Roll Over"
30 pRiKt "GeT wEiRd"
You'll see this on your screen:
lie down
Roll Over
GeT wElKd
Why you don't ns^d NEW here. When you re-u.se a line number, the new line
replaces ihe old one. The lasi program you typed had only one line — line 10.
'Phis new progfam also has a line 10, replacing the old one. It's as if you'd lyped
NEW anyway.
Your computer doesn't care whether the letters are uppercase or
lowercase, or some combination of both. But you've got to be careful how
you type your instructions, Your computer expects to be told exactly what
to do in a way ihat it can understand or you'll get an error message like this
one:
?SyNTAX ERROR IN 10
Computers always do exactlywhai you sayj not necessarily what you tneof^
to say, Even minor typing errors will bring up a syntax error message
(usually with a line number to lielp you find the error). Type:
STEM
and press Return; then type this one-line program and try running it:
10 PRIMT "WHOOPS"— = Watch out!!
t
(lie sure to press Return at the end of the line— this is your last reminder.)
After you run the program, you'll see this message:
?3YNTfiX ERROR IN ID IQ Is the line number,
The elemsntary stuff 3
Even though you and any other human who saw it would know that vou
meant PRINT instead of PRIMT, the instruction baffled your Apple, 'luckily,
most mistakes make your computer show a built-in error message that will
Lcli you what you did wrong. As you program more (and, naturally, make
more mistakes along the way), you'll see more messages to help you
understand how your computer operates. Remember.- the computer
displays error messages to help you correct mistakes, not to tell you you're
a dummy. Treat these messages as helpful guides and not as nagging
annoyances.
Editing: program first aid
You've jusl seen tiiat you have to be careful when you enter a computer
program to avoid introducing a bug, or error Many bugs arc the result of
simple typing errors; you can avoid a lot of debugging later by checking
your typing as you go along.
Retyping a whole line every time you make a simple typing error gets
tiresome very quickly. Your Apple has some built-in features to make
debugging easier.
Type the following line, but don't press Fetum yet:
ic PRINT K "LOOK OUT. YOU BUG"| — = -. Don't prgss Rstum yetl
That A" between the PRINT instruction and the message is going to cause
problems. You could re-type the whole line, but if you had to do that
^vtvy Lime you made an error, you'd never get an^ahing done. Instead,
locate the four arrow keys in the lower-right corner of your keyboard.
Then do this:
1. Press the Left-Arrow key until the cursor is directly over the offending
K
2. Press the Space bar once to erase the K (don t use the Delete key; it
won't work with Applesoft).
3. Using the Right-Arrow key, move the cursor until it is to the right of the
last quotation mark in the line. Clf you press Return in the middle of the
line, you'll lose everything from that point to the line's end.)
4. Now check and make sure your line is correct.
Your line should look like this:
10 PaiKT "LOOK OUTj YOU BUG"|
Now you can press Return and run the program; it 11 work fine.
4 Getting Started
❖ The origins of bug. Back in the old days, computers used vacuum tubes, had a
million miles of wlrcs^ and required large, air-conditioned rooms la keep them
working. Computer folklore has it thai one day a moth got inio the computer
room and flew into the computer. The molh was fried to a crisp, but il didn't die
alone — its demise brought the computer to a dead stop. After searching high and
low lo find what caused the compiicer to "crash," a programmer found the moth's
remains and announced (with no regard for genus or phylum), "Key. There's a
bug in the computer," The rest is history,
Summary and review
In Uiis first session, you learned how to make way for new programs with
NEW, how to execute programs with RUN, and how to put messages on the
saeen with PRINT. You saw how programs use line numbers to arrange
the sequence of irstmclions. Finally, you learned a few things about bugs
and how to get rid of them.
Before you go on to the riext session, experiment with the PRINT
instruction. Write a five-line program; then change the line numbers by
retyping the lines (making the last line the first one, for example) to see
what happens. And don't be afraid to make mistakes — nobody's keeping
score!
SummaPf' and review 6
Arithmetic and Variables
You don't have to know a lot about arithmetic to iearn lo program your
Apple computer. But most programs require arithmetic functions to make
them work. (For example, in a checkbook balancing program you might
want to subtract the amount of each check that you write from the account
balance.) In this session, you'll learn the basics of computer arithmetic.
You'll also read about variables, the storage areas in the computers
memory that hold values. Finally, you'll learn the rules for giving names lo
variables to make them easier to handle — and then you'll be encouraged to
break the rules to see what happens.
You learned in the first session that your Apple displays anything enclosed
in quotation marks after the PRINT instruction. To do arithmetic, use the
PJdN'i' instmction Wiihout quotation marks.
For example, type this program and run it:
10 f^RINT "5 + 5"
20 PRINT 5+5
[n the first line, you told your Apple to print the phrase 5 + 5. But in the
second line, you said, "Add the numbers 5 plus 5, and show the answer on
the screen."
As you might expect, your Apple can do more than just add. In fact, it can
do some extremely complex math. But in this tutorial, you'll stick to the
basics: addition, subtraction, multiplication, and division. Here's a chart
that shows the symbols (called operators) your computer uses to do simple
arithmetic:
B Arithmetic and Voriables
Arithmetic
5 + S -
10
tine 10 printed exQcriy \«tiat was Inside the quotation marks.
Ur>e 20 printed ftie sum of the two numbers,
Operotw Action
+
add
subtract
multiply
/
divide
The addition and subtraction operators are the same ones you've always
used. You've probably seen the division operator before, used to express
a fraction Cas in 7/8). The only one that looks a little different is the
multiplication operator; it's an asterisk (*) instead of anX. Many
programmers use the letter A'" to represent some unknown value, so
somebody decided to use the asterisk Cwhich is like an X with a horigontal
line through its center) instead.
Here's a sample program. Type it; but before you run it, predia what the
answers will be:
Line 20 shows you that your computer can handle fractions — you jusl need
to expres.^ them in a way your computer can understand. For example, if
you mean to tell your computer to determine the sum of two and one-half
plus three by typing this:
you'll gel an answer you hadn't counted on. Your computer will display
13.5 instead of 5-5. It interprets 2 1/2 + 3 as "divide the number 21 by 2;
lake that answer and add 3 to it." Spaces between numbers mean nothing
to your electronic friend.
If you worked out all of the problems in your head before you ran the
program, the last answer may have been a surprise:
70 PSINT 10 ' 2 + / 2 The onsw&T Is 2d. rrot 14!
The result of the calculations is based on precedence. Precedence is the
order in which your computer does mathematical operations.
10 I"R1KT 4 + 51- "
20 PRINT 7.56 - "
30 PRIHT 4 ' 5 '
^0 PRINT -9.6 / 2
50 PRINT 11 -H 12 -13 + 14
60 PHINT 12 / 3 * 4- _
70 PRINT 10 ■ 3 + a / 2——.
Here's simple- oddltlon.
Vouj compLiter handles dQclmnts easily,
Remember; " means multiply.
Here's simple division.
It con cio multiple operotions,
The computer solves problems from left to right..,
... but fheie ate othor considsraMons (read aboijl"
precedence In ttie nsjft section).
Precedence: the order of calculafions
[n general, your Apple docs calculations from left lo right. But all
multiplication and division happens before addition and subtraction. Step
through the calculations in line 70 lo sec how precedence works.
Calculation: 10 * 2 + 8 / 2
Step 1: 10 • 2 - 20
Step 2: 8/2=4
Step 3: 20 + 4 = 24
Use parentheses to change precedence
SomcLimes you'll need to rc-order precedence so that you can first do
addition and subtraction and then do multipiicaLlon and division. For
examplCj what if you meant
PRINT la + 4 / 3
to mean you wanted to add 18 and 4 first, and then divide the sum by 73
Look at the following little program to see how to do it:
SEW
ID PRINT IS -h 4 / 2 Thlscom&&oijt20.,.
20 PRINT US + 4) / 2 . ..but thIs comos 1 1 .
Line 10 first handles the division, then adds the result to 18. Line 2^re-
orders precedence by enclosing the sum within parentheses. Parentheses
change the order of precedence, Whatever you type within parentheses is
solved first, again from left to right and multiplication/division before
addition/subtraction.
If you need to, you can embed parentheses within other parentheses to
show precedence in more complcJt situations. Just remember to go from
the innermost set of parentheses and move outward.
Take a look at this next program and see if you can guess what the results
will be before you run it:
10 Arithmetic and Variables
10 PRINT 0-3) ' 1
20 PRINT 3 ' [ (10 - 6) / 2*
30 PRINT ((4-31 / (9+2)) '2
40 PRIST (((1 + 2S ' (2-lH + ID / 10
Now run the program and see if you were right
Whenever you start using a lot of parentheses, check to make sure that the
number of left parentheses matches the number of right parentheses. Tf
the totals of left and right parentheses are different, you'll gel a syntax error
message.
* Pretend you 're the computer: Every time you write a program or a section of a
program, run it in your head before you fun it in your computer. The more you
"play computer," the more you'll understand how your compuier operates. As
thai happens, you'll automatically type insirjctions the way the computer needs
to sec ihem; you'll soon find iha: you gel far fewer error messages. Try it for a
while and see what happens.
Experiment with your own arithmetic progran^s. Try mixing the
precedence up. jMix in some phrases to label what you're doing. For
example:
10 PRINT ""The 5um Of 12 plus 20, dividad by the tJiCteretice between 5 and 3.5, is "
20 PRINT 112 + 20) / (5 - 3.5)
About unsightly "mnover" lines: If your computer is set to display 40 columns on
your screen, line lO's quotation ran over the edge of the .screen and wrapped to
the next line. The word divided was split in the process. As you go along you'll
pick up little tricks to avoid such unsightly split words; for the lime being, try to
ignore them — your computer does.
So now you know how to use your Apple to do arithmetic. And you can
use it as you would a calculator (although using a calculator is probably
quicker and easier). But the simple arithmetic functions you just learned
become much more powerful when you use them with variables.
Variables
Variables are symbols for values, They're c^Wod variables because tlieir
values can change or vary. Variables look like phrases you forgot to put in
quotation marks:
VariQbtes 1 1
NEW
10 PRINT "HELLO-
ED PRINT HELLO
RUN
fiELLc—- Une 10 prints this.
" — - Uno20's work,
^Th^'^"'' ^ P^^^^^ ^^'^ computer to print just
it The second HELLO is a variable whose value happens to be zero
You give a value to a variable by using the equal sign
Add these lines to the HELLO program and run it:
30 HELLO - 126
40 PRINT HELLO _ Thiswiil show jp oa 128!
RtJN
FELLO
126 —
New vclue fof voriabla HELLO assigned In line 30.
You-ve just assigned the value 128 to a variable called IinLLO Think of a
^'e'S fnn ^ ^^"^P^^^.^^^^^g^ ^O^- Whatever you put into the box stays
nrnlr. ""'"^^ something clse. Add these two lines to your
program and run it again:
50 H£LLO = 330[
60 PRINT HELLO
You can do math with variables. Try the following program:
NEW
IQ fl = 15
20 B = 95
30 PRINT A + B
n'^ter,' 'Tvr!l°lh ""r'n''"" ^^'^"'^tions on other variables well as on
before you run it:
10 LOW =■ 5
20 HIGH = 9
30 SLrH= LOW + HIGH
^0 PRIHT SUM
The sum of variables LOW and HIGH ends up in the third variable SUM
r^'d^'ifbres y^^^^^^^ g~ combinations of numbers
Arithmelic and Variables
10 - ±4,5
I, 20 X - e, 5
' 30 PRINT !H + * 2
40Y-W-X43
60 Z - 3 ' ¥ - 2
I TD PHINT Z
Naming variables
Applesoft imposes a few restrictions on naming variables. Here's a list;
I A variable name must begin with a letter.
■ Characters after the first one can be a mixture of letters and digits (no
symbols).
■ Certain letter combinations (called reserved words) have special meaning
to Applesoft and can't be used in any pan of a variable name. (You'll
learn more about this rule in Session 3.)
■ A name can be up to 238 characters long, but the computer recognises
only the first iwo. (The others are to remijid you what the variable
stands for.)
When you write a very short and simple program, using single letter
variables is a safe way to make sure a variable name doesn't conflict with
another variable. (Your computer sees SUM and SUNDAY as the same
variable because of the last rule in the chart.) But when you begin writing
longer programs, it really helps to have variable names that describe what's
going on.
For example, if you're calculating the area of a circle, you'll need the value
of pi (jt) in your program. You could have the variable X hold the value of
pi (3.141592). It makes more scnsCj though, to give variables more
meaningful names:
10 PI = 3.1415&2
20 RADIUS =3
30 AREA = PI ■ RADIUS ' RADIUS Math: A = FlR^
If) PRINT MEA
Descriptive variable names make it easy for you to see what the program is
doing when you read your code (a synonym for program).
Voriablss 13
'> Siotv only numbers in numeric variables: The kincfs of variables you're learning
about now are called numeric variables. Thai means that you can use them only
to hold the value of numbers. In Session 3, you'll learn about string variables,
which hold anything — numbers, letters, special characters, If you ge[ an error
message like 'I"YPE MISiMATCH, youVe probably ij-ied to give a non-numeric
value to a numeric variable.
Break a few rules
One of the best ways to understand a programming rule is to break it.
Urcak every variable rule there is and see what happens. Go
ahead — question authority. Here are some examples:
REM
10 PRINT IV
RUN
10
Your computer thought you wanted it to print a 1 and then the value of the
variable V. CMI variable names start with a letter.) Variables that you
haven't assigned a value to automatically hold the value 0; a J with a next to
It is 10.
10 PaXNT - 1
RUM
?SirWTflX ERROfi IK la
PRINT is a reserved word; you can't use it as a variable.
IC KIMI = 5
20 MIAMI ^ a
30 PHINT HIMI
Rtm
B
Only the first two characters of a variable name really count. As far as your
Apple is concerned, you assigned the value 5 to mi in tine 10; but you
changed it to 8 in line 20,
rinding variable names that are both meaningful and legal can be a bit
tricky at first. So when you run into a program bug, ihzfim thing you
should do is check your variable names.
14 Arithmetic and Variables
Summary and review
This session taught you how to use computer ariihmetic and variables. You
learned the rules of precedence and how to program your computer to
calculate simple and then somewhat complicated arilhmetic problems.
You found out that variables are storage areas used to hold values and that
the names you give variables should reflect the kinds of values they hold.
And you saw that, like everything else in programming, there arc rules for
naming variables (and that breaking those rules is a great way to learn
them).
Summary ond review
Session 3
The Outside World
up to now, all the informaLion that went into the computer got there
llirough your program lines. When you wanted a variable to hold .some
value, you used an assignment instruction (as in humber = 23, so called
because it (Zsl^j^mj the value 23 to the variable nuhbks). You, the programmer,
gave the program the variable s value. In this session, you'll learn how to
use INPLT, an instruction that lets the program get a variable's value from
the person using your program. You'll read how to construct meaningful
prompting messages so your user will know what informalion the program
needs. And you'll learn about string variables, which let you assign letters
and special characters (not just numbers) to variables.
You'll also learn the difference between immediate e:xefinloii and deferred
execution, and you'll encounter new iasuuaions that let you clear Ihc
screen (llOiMF.) and get an updated listing of your program (LIS'O.
INPUT
The INPUT instruction is at the heart of intcraeth'e programming—
programming that lets the computer and a human hold a conversation.
IXPUT lets you give information to your program while it's running. It
makes the program wait until you (or the person using your program)
types something and presses Rciurn.
Type and run the following program: when a question mark (the INPLTT
prompt) appears on the screen, type a number and press Return:
NEW
10 INPUT A
20 PRINT A ' 5
Your Apple computer prints whatever number you typed after the
question mark. If you typed 3, your screen would look like this:
■ ^ " Voui computet suppites the question mdrk dutomptlccllv.
15
It's )ust as if you had typed A = 3 as a program line. Whatever you type in
response to an INPUT prompt gets assigned to the input variable (a variable
whose value is assigned by the uscr^ as opposed to one whose value is
assigned by the programmer).
18 The Outside Woild
Prompts
The quesUon mark prompts you to type something. You knew what to
type Ca number) because this tutorial told you. But people using your
program would have a hard time knowing what to do if all they had to go
on was what appeared on the screen; a question mark in itself doesn't say
much.
Applesoft lets you use descriptive prompts to solve this problem.
Prompts tell a computer user what to do next. You can use either of two
ways to show what the program wants. First, you can print a line that says
what to do- then use an LNPUT line.
Type this program and run It;
^0 PRIST "I had a tough n.igtit . Whst year is this?"
20 INPUT Year
Now when you run the program, the message on the screen lets you know
that you need to type the year.
You can also use the INPUT instruction itself to print a prompt. A prompt
with INPUT works almost like a prompt Vo lih PRI>JT, except thai the
prompt appears on the same line as the INPUT instruction:
liEW ^ INPUT and prompt.
30 PRINT "and 1 niisaed Christmas."
(Be sure to give the computer an answer when it prompts you for one.)
The semicolon between the quotation mark and the variable name in line 10
is important; you have to include a semicolon when you're using 3
prompting phrase with an INPUT instruction. Note that when you use a
semicolon after an INPUT insUTjciion, your Apple omits the question mark
prompt.
^ Some tips on using PRINT: Line 20 has impilcalions you can investigate on your
own. To gel you siarted, note that;
1. There's a semicolon after the final quotation mark — ihe semicolon teils BASIC
to show the value of the variable on the same line as the quotation.
2. Your Apple does a. little arithmetic on the variable Year.
Here's a program that shows several examples of self-prompting INPUT
lines:
10 INPUT "1 had a tough night. What year is this?
20 PBINT "Oh, great. I thought it was "; Yeac + 1
Nbw stuff horel
Prompts 19
NEW
10 PRINT "TRIVIA PROMPT GAME"
20 PRINT
30 INPUT "How mar.y cards fl,re Ln a deck? Cards
40 INPUT "How fHflfiy U.S. congreaspecsons are there"? CP
50 INPUT "How many Iceys are there on yaur keyboard? ",■ Keys
60 INPUT "How many days aro in a ioap year ? " ; Leap
*> Illegal names and syriiax errors: The irivia program uses descriptive variable
names in all lines except line 40- 'Oie variable name CP is not very descriptive,
but both Congress and Person^; coniain the reserved ward ON. CSee ihe list in
Appendix B.) \X'^cn you get a syntax error in your program and yQu don't know
why, try changing ihc variable names.
More editing: adding lines
Sometimes you have to add lines Lo your program. If the new fines belong
at the end of the program, you jusl type a line number larger than the last
line number In the old program and start typing. But what happens if you
need lo add a tine in the middle? Nothing to it. All you have lo do is type
a line number that's between the numbers that already exist.
For example, suppose you have the following program, and you want to
include a line between lines 10 and 20;
10 PRINT "Kementber tc"
20 PRINT "the dog"
You want to remember to feed the dog. All you do is add the following
line to your program;
15 PRINT "feed*'
Go ahead and run the program. You II see Lliat evcr>'thing turned out in the
right order.
^ Leave intcruals between line numbers^ All the sample programs you've seen in
this tutorial have line numbers spaced 10 apari. If [he current program had been
numbered 1, 2 instead of 10, 20, you wouldn't have had room to insert the new
line, and you would have had to retype the whole program.
Cleaning up with HOME
^'our screen get.s cluttertfd after you've typed and run a few programs. The
HOME instruction cleans the screen and places the cursor at the upper-left
20 The Outside World
corner (the cursor's beginning, or home, position). Each time the
program encounters IIOML, it clears the screen and homes the cursor:
NSW
ID hQME
20 INPUT "ROW MANY POUNDS ARE IN A KTLOSBAM? LB
30 HOME
^0 Ifi&UT *'HOW OLD IS THE PRESIDENT? "f PRES
RUN
The screen cleared with each new question. That way there's no confusion
about what the program expects, and there's no dutter from other
programs.
You can also use HOME without a line number whenever you feci like doing
some light housecleaning. Just type home and press Return.
'I'ry it now:
I TOME clears the screen — it doesn 't clear memory. HOME just erases the
junk cluttering your display. It has absolutely no impact on memory.
(Dun't confuse it with KEW.) But after you use HOME to clear your screen,
you'll need a way to see your program lines again.
LIST
Type LIST and press return to see your program again. Try it now,
LIST
A.S your programs get longer, you'll use LIST more and more. Type the
following program to test the different ways lo use LIST:
MEM
10 HOME
20 PRINT "And Maud Prltchard"
30 PRI«I "waddled the bible-black path"
^0 PRINT "to the baat-ijobl3ing sea"
Sn PRINT "with nary a ffllnd"
60 PRINT "for Mr. Pritchard, dead as biscijits.'^
Fin^t, run the program; then list it. Once youVe listed your program, try
the following variations of the LIST command to sec what happens.
LIST 40 Lists line 40 onlv
L 1 ST 4 Q -
Lists from iin© 4Q To end of program .
LIS*. 4u —
LIST 20 - _ " ' — Lists from beginning to line jSO.
'Lists from line 20 to line 40.
With the small programs you've ^Titten so far, you won't need all these
variations in the LIST command. But later, when your programs are so
large they roll off the top of your screen, you'll want to list smaJl program
segments.
Sfring variables
In Session 2, you learned how to use variables with numbers. You can also
use variables with text. Variables that hold text arc called string variables.
Siring variable names always end with a dollar sign CS), and you deHne ihcm
Cthat is, give tliem values) in nearly the same way as numeric variables:
HEW
10 HOKE
20 fluntS= "Aunt Liazy"
:J0 print fluntS
when you run this program, the words Auntlizzy appear on the screen.
Line 30 works the same as
PRINT "A-gnt Lizzy"
You can put just about an>thmg into a string variable. Unlike numcnc
variables, which accept only numbers, string variables can hold letters,
numbers, symbols — even punctuation:
NEW
10 HOME
20 G?\RBAGES= "All of this jufik -> ^A^S,*^ :;"
30 PRINT GARBAGES
Your computer printed everything between the quotation marks in line 20.
It's important to remember that numbers are not treated as numbers when
ihcy are in string variables. 1'hey rc treated as text — just symbols, a string
(get it?) of characters without meaning to the computer.
Run ihis next program to sec numbers treated at text:
10 HOME
20 AS - "10"
30 B5 = "20"
40 PRINT A$ + B5
Instead of getting 30, you got 1020. The plus sign C+) doesn't "add" the
string variables. (How do you add letters?) K just string.^ them together.
In computer terms, it concatenates them.
22 The Outside Wotld
You can also use string variables with INPUT. You use prompts with a
siring variable INPUT just £3 you do with a numeric variable INPUT. This
next program mixes both kinds of variables:
10 HOME
25 IK?UT "What's ^^our name? ■■; NAMES
33 INPUT "Type your age: NUiyi
53 PRINT NAMES; ^ ^ Note t^s SGmicolon .
SO PRXNT " Is "J Tti era's □ spaeo beforiB tha ] andofterthes,
70 PRINT NL'M;
B3 PR:NT years Did. "
Just to sec what happens, type some letters when your Apple asks for
numbers. (For example, type eighteen instead of the number la.)
As soon as you press Return, you get this error message:
7HEERIE3
That just means your program expected a number and got something else.
Do as it says — re-enter a number (your computer wouldn't He to you), and
everylliing will work fine.
Variables rules recap
In case you've forgotten, here are the rules for naming variables. The last
one applies only to string variables:
■ A variable name must begin with a letter.
■ Characters after the first one can be letters or digits.
■ A name can be up to 238 characters long, but the computer recognizes
only the first two. (The Others are to remind you what the variable
stands for.)
■ Certain letter combinations (called reserved words) can't be used in any
part of a variable name. See Appendix B for a list.
■ All siring variable names end with $.
Debugging
Murphy's law, "If anything can go wrong, it will/' applies doubly to
programming. (Lubarsky's Law of Cybernetic Entomology applies equally:
"There's always one more bug"; but that's for a more advanced tutorial.)
Debugging 23
lixpericnced hackers (another term for programmers) and beginners alike
make all kinds of liltle errors while programming. Debugging a program
(that is, ruthlessly tracking down and cxterminaiing bugs) is a normal part
of creating a computer program; more ortcn than not. it's a major part.
That's why your computer has error messages.
Knowing the difference between immediatcand deferred execution is
helpful in debugging programs. When you type run or new or list without
a line number, the computer does what you want as soon as you press
Return. This is known as immediate execution. When you write a program
with line numbers, the computer defers execution until you run it. This is
called deferred execution. Immediate execution is extremely useful in
debugging programs.
For example, type and run the following program:
IC HOME
20 MONKTfS - "SI. 000"
3D PRINT MONEYS
You get ?SYNTftx ESRGH :h zo mstcad of the S1,000 you expected. List line
20, and you will be in for a surprise:
What happened to k on eys? rfs ail broken up. Type:
As soon as you press Return, you get a syntax error. You have a reserved
word (ON) embedded in your variable name. In your program listing, you
can sec that ON has been separated from m e¥$ in lines 20 and 30. You
can rewrite your program with another variable name, but first test the
alternate name by using immediate execution. Try the following:
There was no error message tiiis time. That means bucks is acceptable as a
variable name. In this case, changing the program takes only a few
seconds^ you've used mokey? only once. But consider a situation in which
you've typed a much longer program, using moneys 25 or 30 time.s — U would
take quite a bit of time to change each instance ofMOMEvs to bucks. It's a lot
quicker testing out possible errors by using immediate execution than re-
writing your program every time you encounter an error.
The trick to successful debugging is isolating the problem, Some error
messages give you the line number where your computer detects the
problem. This helps you i:ero in on the problem. Test the possible
problem from the immediate mode as you saw in the example with moneys
andsucKS. Correct the error in the program, and re-run it to sec if more
2A The Outside World
errors occur. If no more errors happen, then your debugging
succeeded— at least as far as variable names are concerned.
You'll find more uses for immediate execution as you go along.
Experimentation is the key. Try evcj^thing first with immediare execution;
you'll be in for some pleasant surprises.
Summary and review
In this session, you learned that you can get informatjon from the user with
Lhe INPUT instrucUon while your programs are running. He sure to use
descriptive prompts with INPUT; that way people who use your programs
can know what they're supposed to type. Descriptive prompts are to the
users of your programs what descripti,ve variable names arc lo you, the
programmer.
You also learned about string variables. You saw that they work and look
much like numeric variables, except that string variables end with $, and
their values are surrounded by quotation marks in a program line.
The llOiME instrucUon clears the screen for you. LIST lets you see all or
some of the lines of the program in memory to make program debugging
easier.
You also learned thai you can use many programming instructions with
immediate execution lo help you debug program.s.
Summary and review
Session 4
Using the Disk and Other
Devices
As you write longer and better programs, you'll want to start saving them
to U5e again. This session explains how lo store programs onto disks and
how to gel Ihcm back again.
You'll learn about three different kinds of memory CRAM, ROM, disk), with
emphasis on disk memory. You'll see how lo store a program onto a disk
with SAVU:, retrieve the program with LOAD, and see a list of all ihc
programs on a disk with CAT. You'll learn how to gel rid of outdated
programs on a disk by using DELETE.
You'll also learn how to use PR#1 to get a version of your program on
paper instead of on the screen, and how to uscPR^^O to use the screen
again. And you'll end the session with a review of everything you've
learned so far.
Computer memory
RAM .stands for Random Access Memory. RAM is temporary. When you
first turn on your computer, this memory has nothing meaningful in it.
When you write a program or tell your computer to retrieve a program
stored on a disk, that information goes into R^VM. When you turn off your
computer, all of the information in RAM evaporates.
ROM \s Read-Only Memory. It's a kind of memory thai holds information
permanently. The Applesoft BASIC language is stored in this kind of
memory; when you turn your computer off, the language slays in ROM (but
not your program), Nothing lhal you type gets stored in this kind of
memory.
A disk is what you save programs on. Disk drives Cthe devices thai disks go
into) work a lot like tape recorders. With a tape recorder, you talk into
the microphone, and your voice is recorded on m^igneiic tape. Then you
rewind the tape and listen to your voice. Your computer works the same
way, except that instead of using tape recorders to save what's in RAM onto
tape, it uses disk drives to save information onto di.sks. Once you've got a
program on disk, you can "play it back" again and again.
You don't have to worry about the technical details of RAM, ROM, and
disks. But you'll save yourself a lot of grief if you remember that when you
turn off your computer, cver>thing in RAM disappears into electronic
oblivion.
2a
Using the Disk and Other Devices
Files and catalogs
Most well-organii:ed people put written records In files so they can find the
records again. So too with computer records. Programs stored on disk are
also called flics. There arc several other kinds of files, bul the only kind
you have to know about for now arc program files — Ihe name given lo
programs stored on disks.
Making a list or catalog of what files are stored in a file cabinet makes it
easier lo locate a file when you need il. F.s.seniially, that's what your
computer docs when you save a program on a disk. You store your
program by using the SAVE command, and the name of the program is
placed in a catalog. ^XO^en yoy want to use a program, you look it up in the
disk's catalog with the CATcommand to make sure it's there; then you
retrieve il by using Ihc LOAD command.
❖ Commands venus inslmctions—a matter of terminology: That last paragraph
used the term command hcvgt^I times. A command is like an insliuclion In that il
tells Lhe computer lo do something. The difference between a command and an
inscrucdon lies almost entirely in when (he computer doe.s what you wanE.
Essemially, » command is an order chai the computer executes immediately; an
instruction is an order whose execution is deferred. It's just a matler of
lerminology.
How to save programs
Storing a program onto a disk is the easiest thing in the world. You issue
the SA\T- command, giving your program a name you can use later to get it
back from lhe disk.
To get some pracLice^ first lype in this program:
HEW
10 PRINT "This is ir.y very firs^ saved program."
30 PRINT "I'm very proud of it"
30 PRINT "(or I will be, if I can get it backt , ■'
Now you need lo think of a name. Here are the i^jles for naming a
program.
■ A program's name can be up to rifteen characters long.
■ The name must begin with a leilcr.
How to save programs
■ You can use letters, digitSt and periods in the filename, but you can'l use
any other characters, and you can't include any spaces. You can use
both uppercase and lowercase characters, but ihe computer converts all
letters to uppercase.
■ All filenames on a given disk must be unique. But characters in the
name count, not just the first two, and you don't have to worry about
reserved words. So coming up with different filenames shouldn't be
much of a problem.
■ The name should reflect what the program does.
ITcrc are some legal filenames:
CHIiCKBOOK
ADDING. PROGRj\M
AH.1ANDAH.2
NOT. 'i. SALE
These names, though^ are iihgal:
lllesof Name Problem
lONE Begins with a number.
TJlIS.PROGRAMi Exclamation mark is illegal.
.POINT Begins with a period,
A.REALLY.TRULY.KIFTY.PROGRAM Too, too, long.
GRF.AT STUFF There's a space.
CMany people use periods in nienarnes where they'd use spaces if they
could.)
Save your program onto a disk now. You can use whatever legal name you
want; MY.FIRST.FILE sccms like an appropriate one.
Type this line and press Return:
SAVE MY.FIRST.FILE
The disk whirs and kerchunks a bit. When it stops, a copy of your
program is safely stored on the disk. Note lhal word — copy. Storing a
program on disk doesn't have any effect on what's in the computer's
memory.
Type LIST and press Return; you'll sec that the program is still there.
30
Using the Disk and Other Devices
Reading the catalog and retrieving a program
Once you've saved your program to itie disk, type NEW and pre^ Return,
Now you know for sure that there's nothing in memory. (Type list and
press Return to sec for yourself.)
To look at the files on your disk, use the CAT command. You'lJ get a list of
all the flics on the disk.
Type this command and press Return:
CAT
Assuming there are no other programs on the disk, your screen will look
like this:
]CAT
/PMCTICE
NAME
flY . FIKST - FILE
BLOCKS FREE
]
TYPE
$03
240
BLOCKS tlDDIPIED
BLOCKS USED: 40
COf course, your screen will look different if the disk already has other
programs on it.) The program MV, FIRST. FILEi: is now in the catalog. (For
information on what the rest of the display means, see the manual that
came w^ith your computer.) The next step is to retrieve the program. To
do tliat you need a new command, LOAD.
Type this command and press Kctu:n;
LOAD MY. FIRST. E^ILE
Reading the catalog and retrievlrtg a program
3!
You'll hear your disk drive whir a second, and then the prompt and cursor
will reappear. That means your program was successfully loaded into
memory.
To make sure ii's the program you saved, list it:
LIST
Your program appears, just as it was when you saved it,
*t* LOAD does a !\''EW: ^X'^hen you load a program, your compuier first clears ita
mcmoiy of any program that might already be Lhore. This means you don't have
to worry about Iwo progfams being mtxed together (It's possible !□ combine two
programs, but the technique is loo advanced for this tucarial) 'Hiink of T.OAl^ as
having an auLomaiic NEW attached to it.
Cleaning up
If you're really careful when you write programs, you'll save different
versions as you go along. For example, you might have saved these
programs on your disk:
S^lAMPS.Vl
S'1AMPS.V2
STAMPS. V3
If you know for sure that the last version of your program, STAMP5,V3, is
the only one you plan to use, you might as well get rid of the other versions
and free up room on your disk. You delete files by using the DELETE
command,
To delete STAMPS.Vl, type
DELETE STAMPS.Vl PfBSS Rstum.
You'll hear the disk whir, and STAMPS.Vl will be just a memory Cliuman,
not computer). Just think of DLLISTIi as the opposite of SAVE, and use the
same format.
^ DEUiTF.'s not reversible: DELETE is forever. Once you delete a program from
the disk, it's gone. Be sure that you wane to gee rid of a program before you use
DELETE.
32
Using the Disk and Other Devices
For printer owners; printing your listings
So far, you've sent your program to the screen and to the disk. You can
also send your program (and anything else you type) to the printer.
Printing out a program, cfipccially a long one, is ^/fcwe/y helpful in
program debugging; your cxpt-Tience will show you how very true this is.
To list a program on your printerj follow these steps:
1. Make sure your printer is properly connected lo ihc cornputer.
2. Check that you have paper properly loaded.
3. Be sure the printer is turned on,
4. Type pr^l and press Return.
Of you don't follow any one of the first three instructions, your computer
will appear Lo be stucl^;.) The PR#1 command makes everything that would
go lo the screen go lo the printer. If you type LIST after you've typed a
PR#1 command, your printer will clank out the listing (unles.s you've typed
LIST incorrectly — in which case the syntax error mes.sage gets printed).
To see the computer's output on your screen again and to stop using your
printer, type this;
and press Return. The commartd will appear on the printed page; but after
that, subsequent commands and listings will appear on the screen Instead.
Bugs can be tough to fintJ In Itmger programs, especially when your li.5ting
is so long lliat it scrolls off the screen. Printing out your listings can save a
great deal of debugging time.
Type this program and tr^^ listing it on your printer;
KEW
ID HOHE
20 ?B:?iT '^This program will be tested ro my orinner."
30 PRINT "If there's a huq here, the printer"
iC PRINT '^will help IBB treck it down."
LIST
Your primer givCvS you a hard copy listing of the program.
Before you turn off your printer with PR-#0, run the program to sec what
happens. Then type FK^O to get your BASIC prompt G) back on your
display screen.
For printer owners; printing your listings
Using what you've learned
You've had less to learn in this session than in the three previous ones.
Use your remaining BASIC study lime to write some programs that use all
the instructions and operators you've learned so far. Here's a list to jog
your memory:
Instructions
HOME INPUT PRINT
Operators
Commands
CAT DELETE NEW
LIST LOAD PK#1
PR#0 KUN SAVE
Concept*
tmmediate and Deferred Execution Line Numbers with Intervals
Meaningful Names Numeric Variables
Precedence Prompting Messages
Siring Variables
Summary and review
In this session, you learned how to store programs onto disks by using the
SAVE command, and how to gel them back by using LOAD. You learned
how to name programs, and which characters are legal in a name and which
ones arcn t. You saw that CAT gives you a list of all the files on your disk,
and that if you use PR#1, whatever ordinarily goes Lo the screen goes to the
printer. CPR*0 sends information to the screen again.)
34
Using ttie Disk and Other Devices
Loops and Conditions
In liie first few sessions, you learned the rudiments of BASIC
programming. Now it's time to get down to some more advanced stuff.
In this session you're going to learn about three very powerful principles:
Ifjops, rclalionaJs, and conditionals. You'll also read about some BASIC
short culs that make programming easier, and you'll learn some other
helpful instructions.
Loops
I o loop is to go over the same part of a program more than once, Tor
example, suppose you want to get ten names with INPUT and print them
one after another onto (he screen. It would be a lot easier to repeat the
part of the program with the INPtTT instruction than to write ten separate
lines with INPUT:
NEW
ic nom.
20 INPUT "Ginur-ia nere: NflJ<E;$
30 PRINT NAMES
^0 HowdovoLigetbacktollne20?
What you need is some instruction that lets your program loop back to line
20 to get another name. That instruction is GOTO.
GOTO
The GOTO instruction directs the program to go to any line you name.
This program clears the screen, ilicn slcips to (or branches to) line ■lO
iastead of going to Hne 30:
NEW
10 HOME
20 GOTQ -3
30 PRINT "Hey! I thought I was next!" Ttils never gets fainted!
■30 PRINT "I'm the anLy line you'll sec!"
Here's another example. Type Ihc first program of this session, but tliis
time type
^0 GOTO 20
36 Loops and Conditions
for the last line. Then list the program. It shauld look like this:
10 K.CKE
20 IKPUT ^'Giinma a name: NAMES
30 PRINT NAMES
40 GOTO 2Q
This program repeatedly asks for a name and then prints out what you
type. The program will go on doing this forever as long as somebody
keeps typing in names (or until somebody pulls the plug); every time the
program reaches line 40, it goes back to line 20.
^ Infinite loops: Wiat youVe got here is an infinite loop. Sometimes, infinite
loops can be helpful — this isn't one of those times. To get out of ihc loop before
you run out of names (or pattcnce)^ press the keys marked Control and C at the
same time; release them and press Reiurn, That's called pressing Control-C;
you'll run across ihis Lerm often if you read computer books and magazines.
When you press Conirol-C, your computer will announce:
BREAK IN 2
The message means that you "broke into" the program at line 20. Wlien a
program gets stuck (or hangs), sometimes the only way to regain control is with
Control-C
This program solves the problem of getting lots of names without retyping
INPUT lines again and again. But it's out of control. You need a way (other
than Conlrol-C) of getting the program to stop looping when you've had
enough.
CondiHonal branching with IF.. .THEN
BASIC has a two-part instruction called IF. ..THEN. It gives your program
ihc power to make decisions — which, as it turns out, is just what you need
to solve the infinite loop problem. The general format of IF. ..THEN looks
like this:
IF <something is irue> THEN <perform some aciion>
An IF... THEN instruction decides whether or not something is true. If wha.t
you say in the first part between the words fF and 77//iA''(callcd the
condition) is true, then your computer docs whatever you put after THEN.
If the condition is not true, then the program ignores everything after
THEN and drops to the next line.
To see this in action, add two lines to your Infinitely looping program:
25 IF NAMES - "Enaugh" THEN GOTO 50
50 PRIKT "And that ends the name list."
Cortditlorwl branching with IF. ..THEN
37
Here's the whole listing:
10 HOME
2D INPUT "GirmiB 3 name: NAME?
25 IF NAMES = "efiough" TriEN GO^D 5
3D FBIKT NAHE5
40 GOTO 20
50 PRINT "And Chat ends ^he r.ame list."
Run the program now; after you've typed 2. few names, type enough and the
program ends.
Building on Ihe model
Going by the model IF <somaihing is true> THEN <perform some action>,
in the previous example the something-thal's-tnjc (the condition) \?,NA$ =
"enough." When Nx\S was an>thing excGpt "enough, ' the program went on
looping; when it was enough, the program branched to the final line. The
branching was the perform-some-action part.
•> Start a saving plan: As you type in your programs, you should get into the habit of
saving ihem to yuur disk before you run ttiem. Then, save ihcm often as you
develop and change them— once every ten minutes or so will do nicely. There'll
be situations when even Control-C won't get you out of trouble (like, for in.stance,
when your little brother playfully flicks off the power switch). If you save the
program aften, you won't have to recreate and retype your latcsl refinements.
Relational operators
Here arc some more examples of IF. ..THEN instructions. Pay careful
attention 10 the conditions; you'll see some symbols you haven't seen
bufore:
IF HA$ - "QOIT" THEN GOTO lOD
IF ftS "APPLE" TBEN PRINT "TfOQ LOSF-!"'
IF SUM > 10 THEN X = 50 — - — .
IF COUNT < 100 THEN GOTO 20
o means "not the same gs"
> means "gfeater than".
■< means "less tf>onV
Those litilc angle brackets are catted relational operators. They describe a
reialion that exists between two things. Here's a chart that shows ail the
relational operators and what they mean;
38 Loops and Conditions
opera lor Meaning
> greater than
< less than
equal to
o not equal to
>= not less Lhan
<- not greater than
The next two programs give you some examples of what you can do with
rclationals, GOTO and IF.. .THEN instructions. They also present you with
.some challenges, leach you a new insLrucUon or Lwo, and give you a few
BASIC ,short cuLS.
Comparing Values: This program asks you for two numbers, then telis you
which number is the lower one. The program has a few surprises in it to
keep you from getting bored.
First, type the program. Then see if you can figure out what's going on
before you run it. Finally, run it and see if you were right.
LO HOME
15 PRIKT "To end tJie program, cype a for the Eirst number,"
20 IHPUT "Enter thE first number: ": Nl
25 IF Kl = THEM EUD
30 INPUT "Enter the second number: N2
3S IF Nl > m THEN GOTO IDO
150 IF fJl < K2 then goto 200
45 PRINT "Those numbers are the sameL'^ — H.O\W dOGS this WOrk 777
50 GOTO 30
LOO PRlCJt N2; " is lower than Nl
110 GOTO 2Q
200 PRINT Nl;" is lower than "; N2
210 GOTO 20
Here arc some questions for you Co consider before reading further:
1. There's a new instruction in line 25 — FND. What docs it do?
2. Line 45 will print its message only if both numbers you type for lines 20
and 3fl are the same, why?
How The Program Works: Line 15 leis you know what to do to stop tlie
program without using Conu^ol-C. ITie END instruction in line 25 does the
work of slopping the program — but only if you type a 0. Line 45 is
Retatlonal operators
executed only when values for Nl and N2 are the same. To see why, look
at the two previous lines. Lme 35 goes lo one part of the program if N2's
value is lower than Kl; line 40 goe.s to another part of the program if the
opposite is true. Being the literal "thinker" that it is, your computer
continues on to the next line (line 45) only if there's no reason not to — in
this case, if both values are the same.
Assigning Variables: This nc3rt program shows how TF...THEN can assign
diffcrc^nt values to variables. In this instance, the values are different words.
Clhey could just as well be numbers.)
Type the program. Before you run it, figure out
1. What are all those question marks for?
2. What's strange about line 80?
3. What's line 80 for, an>'way?
Lie sure to figure out the challenges before you run this zoologically
questionable program:
HEW
10 HOME
20 ? "1. SWIMS"
30 ? "2. WRICKS"
40 ? "3. "LIES"
50 PRINT
60 PRINT "Think of an animal. Ther. chocse a."
65 ? "numbei tJiaC best describes how your"
70 IBPUT "animal movES. KUMBER
SO IF NaKBER > 3 THES 10
90 IF NUMBER < 1 THES 10
100 IF KUMBES = 1 THEN ANIMALS -"Fiah"
110 IF NUMBER = 2 THEN ANIMAL$ = "Kairtnal"
120 ir NUMBER = 3 THEN ANIMALS = "Bird"
130 PRINT
2D0 PRINT ■"I bsc your ai^lTr.al is a ",■ ANIMAL^
Those question marks are a short-hand way of typing PRINT. Saving four
i<ey5trokcs each time you want to u.se PRINT can save you loLs more lime
than you think. When you list your program, each question mark will be
convened to PRINT.
Line SO i$ peculiar in that it leaves out the word GOTO. It turns out that any
of the following forms work for the GOTO instruction within an IF.. .THEN:
ir NUMBER ^ 3 TITEN GOTO 10
IF NUMBER > 3 TIIFN 10
IF NUMBER > 3 GOTO 10
In other words, you can omit THEN or GOTO — but not both.
40 Loops and Condilions
The purpose of lines 80 and 90 is to set traps to make sure anyone using
the program doesn't put in a number that's beyond the range of choices.
Traps give your users another chance in case they make a mistake (which is
an annoying human tendency).
Use REM for remarks
The REM instruction lets you write notes to yourself about what your
program does, and lets you include the notes in the program. These notes
show up only when you li&t your program; people can't see tJiem when
they run it
For example, you can use REM instructions to keep information about the
program handy, or to tell you what the program segment is doing:
lOQ BSM ^* ******** MAIi-ai* K «**-ki*'ll-a****-»r-'
110 REM The Great flinerican Computer Program
115 REM by Throckmorton Et:ri,bbI«inongec
120 REM Version 16.5
125 REM Jtily fl, 1997
13S HEM Clear the screen
14 HOME
145 COMMENT? = "REM C:ornment.5 don't appear on the screen."
150 REM. Print a. moss^ge qn the screen
1S5 PRIHI COMMENTS
160
ItEM instructions are reminders for people, not for computers. REM
instructions do nothing to your program. When the program reaches one,
it ignores the REM instmction (and anything after it on the same line) and
goes on to the next line.
*> Put program name in a REM line: Make the first or second line of your program a
REM line coriiaining die program's name. Then, when you change the program
and wani lo save the new version onto a disk, you'll always know what name to use,
Practice time
Yqu covered a lot of ground in this
with what you've learned. Co back
Try to "break" some programs; find
session. Before going on, experiment
and change the example programs,
the limits of the instructions you
Practice time 41
learned in this session. Certainly write some programs of your own. Make
mistakes — they're free.
Summary and review
This session showed you how your computer can loop and malce decisions
(ihac is, process information), Vou use loops lo repeat a process several
times. Instead of having to repeal ihc same hnc throughout your program,
you can use GOTO to repeat the lines. This saves a lot of time in building
your programs.
The IF. ..THEN in.-iLrucLion is your computer's "decision maker." With
lF...THtN, you can branch Lo different options and jump out of infinite
loops. You can trap mistakes with IF...THEN to make sure the person
using your program types informalion for INPUT instructions within the
program's range.
You learned some short cuts for writing GOTO instnjcLions within
IF...T11EN instruaions. and you saw how to use the question mark in place
of PRINT.
Finally, you saw how to use liliM to remind yourself what a particular part of
your program docs. By using REM throughout your programs, you can
clearly organise your program lines; by marking program segments to
make ihem easier to fmd, you make debugging easier.
42 Loops and Conditions
Session 6
Graphics
Up to this point, all you've seen on your Apple compuler is text. But you
can also produce some wonderful color graphics. Your computer has
several graphics modes; in this session you'll learn the one called low-
resolution grapliicsL (It's the easiest to use.)
You'll learn the difference between your computer's text and graphic
modeSt while learning the GR and TEX'f instructions. You'll see how to use
COLOR= to set one of sixteen colors to use with PLOT (for plotting points),
VLIN (for drawing vertical lines) andHLIN (for drawing horizontal lines).
Besides all this, you'll learn the RND instruction for producing random
numbers — which you'll use, in turn, to produce some pretty snazzy
graphics.
Text and graphics
Your computer has separate modes for text and graphics. (A mode is any
of several ways a computer interprets information,)
To get started, you need to know two instructions — one to get into
graphics mode and one to get out. When you turn on your computer, it
automatically goes into text mode. When you type the instruction GR for
graphics, your computer goes into graphics mode.
Type the command
GR
Cdon't use a line number) and press Return,
Your screen went blank, and the cursor popped up at the bottom of the
screen. The top of the screen, above die cursor, is for graphics; it takes
up 20 of the screen's 24 lines. The bottom four lines arc for text.
❖ For nrm-color users.- Everything in this session assumes you're using a color
monitor or color [clcvisian set. If you're using a black and while TV or a
monochrome monitor, the shapes you draw are displayed in diffcrcni patterns
instead of in colors.
44 Graphics
Type and run this program:
NEW
10
2 COL0R= 3
30 PLOT 19,
100 PRINT "Purple Square on Blacfe Field [19S&]"
Turn on graphics
Pick Q cotor,
Hot a point.
Great crt nlwoys has a title.
A40-by-40 canvas
The low-resolution graphics screen is a 40-by-40 grid. The PLOT insCruclion
places a block in the horizontal and vertical positions you specify. PLOT 0,
would place a block in the upper-left corner, and PLOT 39, 39 would put
a block in the lower- right comer.
Add the following lines to the program you just typed to see ihe limits of
PLOT. (Don't worry about not being able to see the rest of your program;
you'll see it all again In a minutej
40 PLOT a,
50 PLQT 39, 39
RUM
When you run it now, you'll see three blocks running diagonally down the
screen. The one in the upper-left corner is position 0, 0; tlie one at ihc
lower-left is position 39, 39. Here's what the whole matrijc looks like:
0,0
19, a
19.39
39,39
A d!>bY-4Q convQS
Before continuing, sec if you can ploi blocks in ihe lower-lefl corner,
upper-fight corner, and the middle of ihe left and right sides. Once you
know tiow to do that, you can plot an>Tvhere you want
Seeing your listing again
When you added new lines lo your program, all the text above the new
lines scrolled out of sight behind Ihc graphics. To see your listing again,
you'll need to get back to text mode.
Using immediate execution (that is, giving an instruction without a line
number), type ;
and press Return.
The strange pattern you sec is the result of your Apple looking at its own
graphics symbols and interpreting them as text. To humans, it's just junk
Cor Punk A.rt), Type:
HOME
and press Return. Then list the program. If you got the last program
right, your listing looks something like this:
LIST
10 GR
20 COLOR- 3
30 PLOT 19, 19
40 PLOT 0,
50 PLOT 39, 39
SO PLOT 0, 39
10 PLOT 39,
80 PLOT 0, 19
90 PLOT .39, 19
lOa PRINT "furple Square on BLack Field {19^6)"
46 Graphics
Plotting colors with COLOR=
The COLORS insLruction Clhe = is part of the insimction) lets you decide
what colors go where. Here'.? a chart of all the colors you can use:
N^umbei
Go tor
Numt:>«r
Color
Black
a
Brqwrx
1
Magenta
9
Orange
2
Dark Blue
10
Dark Gray
3
Purple
11
PEnk
4
Dark Green
12
Green
5
Gray
13
Yellow
6
Blue
14
Aqua
7
Light Blue
15
White
The COLOR= insiruaion by itsdf won"t add color to anything. It colors
only what you draw on the screen. The color you set with COLOR= slays in
force until the next COLOR- insiruclion.
Add this new line to your program;
65 COL0R=13
Now run the program and see what happens.
❖ Vncluttering the text: You've got only four lines of tcxi when you use graphics
mode; you don't need to have one of those four lines clucicred up with a left-over
RUN instruction. Aesthetics are, after all, important. Adding a HOME
instruction early in tiic program (say, ai line 5) will take care of the problem
nicely.
Using variables for plotting and coloring
You can use variables for plotting points and setting colors. Instead of
using absolute numbcc as in COLOR= 10 or PLOT 10, 20, you can type COLOR-
HUE or PLOT COLUMN, ROW.
Type this next program. Before you nin it, see if you can figure out what's
happcriing:
Using variables for plotting artd coforing
47
NEW
IC GR
20 C0LOB= 11
30 PLOT COLUMN, ROW
4 COLTjKN = COLUMN + 1
5D IF COLUMN > 39 GOTO 60-
■60 ROW - ROW + I
70 GOTO 30
80 END
1 1 is pink.
rnitJaf volue of all variables Is zero,
Don't panic: explanation ta fallow,
39 Es hlghesl column number on giid
Do If Qliogain.
Incrementing columns and rows
Line 40 is called a counter in computer terms. Every time the computer
executes line 40, the value of the counter (called COLUMN) increases by
one. In everyday language, the line says, "Take the old value of COLUMN
and add 1 to it. l-rom now on, use the new value." The original value of
COLUMN is (all variables start with a value of 0). After the computer
passes line 40 the first time, COLUMN holds 1; after the second time, it
holds 2. And $o it goes until COLUMN holds a value greater than 39
(according to line 50), and the program ends.
<• For budding comptuer geniuses only : Draw a diagonal line that crosses Lhe Hret
one — that is, one that starts at the upper-right corner and goes to the lower-left
It's tougher than it sounds, but once you figure ii out, its .simplicity wilt asloimd
you.
Maybe,
Hint: Stan at 39 and work backwards.
Drawing horizontal and vertical lines
The PLOT instruction creates one block at a time. To draw a vertical or
horizontal line with PLOT, you could program a sequence of connected
blocks, just as you did to make a diagonal line. With Applesoft BASIC,
rhoueh, it's a lot easier to use IILIN (for horizontal line) and VLIN (for
vertical line). You use the same plotting coordinates as with PLOT. Por
ni.lN, you put in the beginning and ending horizontal pos\\\on^ at a vertical
position with the AT instruction:
HLIM FIRST, LAST AT ROW
For \'L[N, give the beginning and ending vertical positions at a horizontal
position:
vIjIh first. Last at column
45 Graphics
Look at this next example to see how to make a cross on the screen:
NEW
10 GR
20 COLOR = 15
30 BLIN 10,30 AT 19 Draws o line left to right
VLIN 10,30 AT 15 Draws a line Up ond down.
Lines 30 and 40 look identical except one uses ITUN and the other VLIN.
As an exercise, change line 30 so that instead of a cross, the lines make a T
with the horizontal line right across the top of the vertical line,
A universal line-drawer
This program lets you put in different values to draw different lines. Use it
until you get a feel for where different values draw lines on the matrix:
KEW
5 TEXT
10 HOME
2Q INPUT "Beginninq block of HLIN; HB
3a IHPOT "Ending blocK of HL-IN ; ",■ HE
150 INPUT "How for HLIN; ";HP
50 IHPUT '^Beginr.ing block of VLlil: "rVB
60 INPUT "Ending blocJt of ULIN: ";VE
7P INPUT "Column tor VLINi ";VP
100 HEM •••*•*•♦••***•**•*
110 HEM DRAW THE LINES
120 HEM
130 GR
' COLOR- 15
15D HLIN HB, KE AT HP
16D VLIH VE,VE AT V?
170 ihpuT "More lines (Y/N)? "; ANS
IBO IF AW5 - "Y" THEN 10
Try different values until you can predict exactly where the vertical and
horizontal lines will go. just for the experience, emer values beyond the
range of the matrix (that is, greater than 39). For example, enter a value of
50 to see what happens. Learning what error messages mean is just as
important as learning how to do things wilfiout getting error messages.
Later, whcrt you make a mistake (and everybody makes mistakes while
learning to program), you'll have a better idea of how to fix it.
Before you go on, modify the program so that it asks you what color you
want to use. If you're reaHy feeling on top of things, add some code that
Drawing horiZDntol and verticai lines
displays the line coordinates at the bottom of the screen; the resulting text
should look like this:
Harizontal line from 10 to 3S in row 25
Vertical line from 16 to 26 in coiunun 25
Random graphics
Your computer has a random-number generator built into it. With it, you
can have your computer pull numbers out of its electronic hat. The RND
instruction by itself generates random decimal numbers between and 1.
Try this program;
HEW
IQ TEXT
20 HOME
30 COONT - COUNT + 1
ACl PRINT RND [ 1)
&0 IF COUNT = S THEH GOTO 70
60 GOTO 30
TO END
Last piogram used graphics.
CJearttisJunk,
Add one to counter.
Print a random numbBi,
Rve mmbers pflnted yeff'
If no, get another random mjmbBr.
Itien end.
RND always prints a decimal number between and 1. But by multiplying
whatever it produces by some whole number, you can make it cough up
numbers your computer can use to make graphics.
Change line 40 to this:
PRINT RMDj 1) - ^0 Pofonihsses after J?ND Fsqulrsd.
Now run the program again. All the numbers arc greater than and less
than 40.
Parentheses required with RND: You must foUow RND with a number enclosed iti
parenihescs. To make sure RND produces a difTercnt series of random numbers
every time you use it, use 1 or a. higher number. CExpcrimentors: lo get a
repeating series of numbers, use or a negative number.)
Type and run this variation on the same program, it puts each random
number in a variable as the random number is produced:
50 Graphics
5 TEXT
10 HOME
20 NUMBER = RND ( 1) ' 40
30 PRINT NUMBER
40 IT NUMBER > SB THEN CQTO 60
SO GOTO 20
60 PRINT "That' s it ! "
10 END
This program runs until the random -number generator produces a number
greater than 38. Sometimes it lists a lot of numbers, and other times just a
few, depending on how soon a number greater than 38 comes up. Notice,
by the way, that the program generates numbers between and
39.9999— never any number as high as 40.
All you do to generate random graphics is to use randomly generated
variables in PLOT. You can also use randomly generated numbers to
produce different colors as well.
Type and run this next program for some colorful results;
10 GR
15 REM COLORS 0-15
20 HUE = RND{ 1) ' 16
25 REM hC.i^IZONTAL VALUES 0-39
30 COLUKN = RND( H ' 40
35 REM VERTICAL VALUES 0-39
flO ROW - RHD { l! * flO
50 COLOR - HUK
60 PLOT COLUMN, HOW
10 IF ROW > 39 THEN END
80 GOTO 2Q
What about the fractional part? A graphics instnioion looks ori]y at the whole
pan of a number, ii ignores the fractional part. To a graphics insmioion,
39 999999 is 39; 1,1111 n is ]; and any posiiive numberless than 1 is 0.
A Minor Challenge for You: Nothing heavy — just change the program so
that it randomly generates horizontal and vertical lines of random length.
Random graphics 51
Summary and review ^^^"^^^"^^"^^^^^^^
Color graphics add another dimension to your programminfi You cir,
creaLc useful programs with them, and they're loi. of fun lo plav with
Low-resolution graphics make rough flgures, but they have a^ot o^rnl'.r
and make good graphs. You use PLOT, HL N ™7and COLORi,l™»
.vuh other progr.™mir,g instructions to'buM g™hlcT4e° The^'™^
anv ran^n"? ^PP'^ can automatS iy Ihurn out
^Snhirf ™- ^™ =™bine RN'D and the
graphics mstrucfons, you can create a kaleidoscope of shapes and colors
52 Gfaphl cs
Session 7
Controlled Loops
lo ?o ]o?ituhToTo""p'J'' feara .bout loops. Vou already know how
in^^r^Jr ^ J u , '^^"^^ ^bout the FOR \ NEXT
xecu rV^J-nV'^ ^'"^r ^'^^^"^^ times ^\oop get.
P^orZ exlcut Ln? ^'u'' "'^"^ ^^^P^ ^^'^^ dawn
'Ilie session md. with a list of all the commands, instructions operators
and programmmg concept. y-ouVe learned so far; the list ^ImprS
FOR\NEXT
You saw in Session 5 how to use a counter with IF...THEN to conrrni h^w
many t.mes your computer performs a loop:
NEW
10 GR
2 COLOR- 11
30 PLOT COLUMN, ROW
40 COLUMN = COLUMN + 1
50 IF COLUMN > 33 GOTO ED
60 RGW - ROW + 1
7Q GOTO 3D' = .
eO END
structure of this two-part instruction: ^^^nicr. ticres ttic
FOR < variable > = < slart > TO < finish >
< instruaions in hers get carried out >
NEXT < variable >
This program uses PORVnexT lo repeat a loop ]0 lime.. Type and run it:
■loop starJs here.
■ Here's the countSf ,„
, ,. to get vou out of ttis loop.
toop ends tiers.
Controlled Loops
Lost program wos graphics; restores test mode.
MEW — -
10 TEXT'" '
20 HOME ' '
30 FOS ROUND = 1 TO 10
40 PRINT "This is round #
50 NEXT ROUND
RO'JMD
This Is the FOR part..,
...cll Instructions within ttie loop get BKBCuted...
., .and this is ths next port,
Clears away the Junk.
When you run this program, the value of KOUND goes From one to ten.
The variable ROUND behaves just like any other variable, and as you see on
your screen, the numbers represent the values the loop generates. All of
the lines between the FOR and the NEXT arc repealed until the loop
reaches its maximum value. In this case that value is ten,
You can start the loop at any value you want. Here's a bunch of line 30's
you can subslilule Cone at a time, of course) to see what happens;
iO FOR ROUND - TO 20
30 FOR ROUND = -10 TO 10^ — = Begin With Q nsgatlv© number,
30 FOR RCUKD = 128 TO 255
instead of using numbers to set up the FOKXNEXT loop, you can use
variables. For example, the following program lets you use INPUT to set
up ihe beginning and ending values of the loop:
NEW
10 HOME
30 IWPUT "LowHBt numbar: LOW
30 IKPDT "Highest nuTT.ber : HIGH
■10 HOME
5Q FOR NUM = LOW TO HIGH
6Q PRINT HUM
^0 NEXT KUH
The FORVNEXT loop works equally well with graphics. By selling up a
FOIUNEXT loop, you can draw diagonal lines lo go with your vertical and
horizontal ones. Here's the original program:
FOR\NEKT
10 GR
50 COLaR= 11
30 PLOT COLUMN, ROW
10 C01.UHS = COLUMN + i
50 IF COLUMff > 39 GOtq
63 KDW - ROW + 1.
10 SOTO ^r. .
SC END
Here's the FOR\NEXT version:
20 COLOR= 11
FOR CoaHT = TO 39
4 PLOT COUNT, CQUigT
50 HEKT COUNT
Loop starts here.
Here's fhe cojnfer
■ — . to get you out o( tne loop.
— Loop ends here,
L^rST^P w^^^ or skip nu.be. in . program,
increment '^^^^^^^ ^P^^^^V l^e direction of the count and the
For example, thi. program counis by 5's. Type and run it:
NEH
5 TEXT
ID HOME
20 FOR HUMaEB - 10 TO TOn ^tpv ^
3C PRINT — Hore'stherirBtofooKot.
^0 KEXT HUMBER
And this one counts backwards:
13 HOME
20 FOF COUNTDOWN = ID TO ST^p -i
30 PRINT COUNTDOWN
40 MEXT COUNTDOWN
50 PRINT "BLAST OFF!"
OMve extra points if you can draw the rocket)
T^:;^'Zi::zz;^/--^ ----
ContrallGd l-oops
KEW
10 GR
20 fOR BOUNCE = TO 39
Sets color to White.,,
,. . so you Cart sea tha block.
30 CDLaS = 15- "
90 PLOT 19, BOUNCE
50 COLOR =
60 PLOT 15, BOUNCE
Sefs color to black...
... so you can erase It.
70 NEKT BOUNCE
100 REM -*t**tAJrA-t,*
110 REM BOUKCE UP
12Q REM *«■"*•*»■***•■»
130 FOR BOUNCE = 39 TO STEP -1
no eOLOH = 15
l&O PLOT 19, BOUNCE
160 COLOR - {J
no PLOT 19, BOUSCE
150 NEXT BOUNCE
You can see how easy that was to do with a backward STEP. By the way,
the ball will keep on bouncing if you add :
190 GOTO 20
It'll get really pretty if lines 30 and 140 read:
C0L03= RND( U ' 16
To make the ball bounce diagonally^ change — well, you figure Uiat out on
your own.
Sometimes you'll want to slow down your program so that you can see
things happen on the screen that ordinarily go by too fast.
For example, type and run this next program lo print a message on the
screen, dear the screen, and print another message:
Delay loops
NEW
2 TEXT
5 STALL = lUQO
10 HOME
20 PRIHT "A VERY IMPORTANT MESSAGE"
30 rOS PAUSE-1 TO STALL
35 next pause
'jO home
iO Pf^INT "B" r.".:?::^ 10 SAVE YOUR PROGRAMS
Chongs this value to chonQQ ttie pause tength.
Show messoge
...hold It,.,
...clear tTte screien .,.
...show nnesiiQQ©,.,
.ho!d it-
50 FOR PA'JSE^l TO STALL
SS NEXT PAUSE
7 HOME
90 PRINT "BEFORE YOU TURK OFF YOUR COMPUTER!"
...clear ttie screen.
Delay loops
The cmpiy FOR\NEXT loops between showing the messages and the
HOME instructions give you time to read what's on the screen, (Take out
lines 50, i5, 60, and 65— just type their line numbers and press
Retum-and the mefJsages will Hy by too fast for you to read when you run
ine program.) '
Use delay loops when you want several messages to be presented
automatically, and when you don't want to press any keys to see ihe next
message. You can make Hashcard-type review programs with shoit delay
For a spelling quiz, have a word pop on the screen long enough to be read
but not long enough to be spelled. Here's a quick one to try:
NEW
ID^HOHE ~ ^ Change tNs voru© to change the pause lengm.
20 BEH ******** "*-TH«»**-tw**
30 HEM SPELLING KOBDS
iO REM ***1rir*
50 RS - "DUCK"
50 as - "JEWELRY"
70 CS = "PR0GiW5HING"
1 □ D fi£M *-»Fini***»**i*i.„»,
HO HEM SPELLING TEST
120 REM '"'»*****-*i>nii*..*
130 FaiKT AS
140 FOR LOOK = 1 TO STALL Here's a dofoy Joop.
1^5 NEXT LOOK
150 HOME
163 INPUT "S^ELL THE WORD SPELLS
i'bo mil^BT ^ ^ """"'^ ' 1— Counter adds up correct spellings.
190 FOB LOOK = 1 TD STALL Another doloy loop,
195 NEXT LOOK
200 HOME
210 INPUT "SPELL THE WORD SPELLS
220 IF 5fELLS = BS THEN HIGHT - RIGHt+i
53D PRINT C$
IT. IZrlZ.^ ' ™ "^^^ Va. *,av loop,
250 HOHE
250 INPUT "SPELL THE WORD "; SPELLS
270 TF SPELLS = C$ THEN RIGHT - RIGHT +1
2B0 iiOHE
290 PRINT "Ygu got RIGHT; " words right."
You can Change the values in the delay loop Oine 5) to give yourself more
or less time to see the word.
58 Controlled Loops
A quick review
You've come a long way in programming already, so now would be a good
time Lo review what you've learned in these first seven sessions, In general,
it's important to keep tilings simple — take programming a litlJe chunk at a
time. Here's a list of evcr>lhing you've learned so far. If you've forgotten
any of these terms, look them up jn the glossary or check the index and ga
back to the appropriate session to read about them again:
Commands
CAT
LIST
PR#0
inslructlons
COLOR=
HOME
HLIN
PLOT
REM
Operators
+
/
<
DELETE
LOAD
RUN
END
FORlSTEP]\NEXT
IF.. .THEN
PRINT
TEXT
(
>
>=
Concepts
Cou nier
Immediate and Eteferred Execution
Loops
Numeric Variables
Prompting Messages
NEW
PR#1
SAVE
GR
GOTO
INPUT
RND
VLIN
Delay Loops
Line Numbers
Meaningful Names with Intervals
Precedence
String Variables
A quick review
Experiment before you continue
The final ihree sessions give you some refinement on the instructions and
techniques youVe learned so far, and introduce some more tricks and
Lcchniqucs. Before you go on, use what you've learned to invent your own
programs and to experiment. It's important to enjoy what you do with
your computer, and by writing programs that do things you like, not only
will you learn programming, but you'll have a good time as well
Summary and review
In this session you worked with loops again— but these were controlled
loops. You refined your use of counters and discovered a new loop called
l-OK\NIiXT. You learned something about computer animation, and you
saw how to slow do^n a program by using delay loops. Then (unless you
took this opponunity to challenge authority) you went over all the
instruction.^ and concepts you've learned so far. and you created new
programs of your own design.
60 Controlled Loops
Session 8
Programming With Style:
Modular Programming
fact, at the end of th,s session, you'll be assigned the task of consiirjclinp a
program to balance a checkbook. ^^ii:>iiuciing a
Notice the word cOTislruciing in that last sentence. The best oroPrams
Wust lists of code lines; rather, they're wcll-ptanned cdleSs o
^o^Tt^ .T' h ' '''^ "^'^ ^^'^ ^^^^^^n. you're
moSulS organisation .nd the concept of program
GO$UB\ RETURN ' ^
Vou'il often want to do the same thing in different parts of a proar.m For
shornroL"r/r"' ' ^^^^ ^^"^ ^^^^^ ^^^f' ^'^^^ in aTairly
short program:
60 FOR PAUSE = I TO STALL
70 NEXT PAUSE
Imagine a program in which you used rhe same lines ten twenty or thirtv
t.me.-.nd how tiresome typing the .ame thing ag.in and ag^^in wo^ id ^
use) Now consider the more common siiuation, where the repealed
roxitm^ (that .s collection of lines that does one specific function) father
than bc,ng just four lines long, is 10 or more lines long. IW the time yoj
were fm.shed, you'd wear your fingers down to the second knuckk ^
U-fe a rnu^'^^'^T '."f ^^^^ ''"^^ ^^^^ situation.. You
same line numbers) again and again.
Here's how the PAUSE program looks without GOSUD\RETURN;
62
Programming Witti StyJ9: Modular Programming
5 STALL = 1000
10 HOME
30 PRTNT "A VERY IMPORTANT MESSAGE"
30 FGH PAUSE^-l TO STALL
35 NEXT PAUSE
^0 HOME
50 PRINT "BE SURE TD SAVE YOUR PROGRAMS"
60 FOR PAUSE = 1 TO STALL
65 NliXT PAUSE
TO HOME
BO PaiWT "SF,FORE YOU TUHN OFF ^OUR COMPUTER ["
And here it is with GOSLBVRETURN. Type and run it:
KEW
5 STALL - lOOS
10 HOME
20 HL53AGE^ - "A VERY IMPORTANT MESSAGE"
30 ECsUB 21P ■ So to a subroutine ot line 2 ID.
4& MESSAGES = SURE TO SAVE YOUR PROGRAMS"
SO GOBUa 210
60 MESSAGES - "BErOKE YOU TURN OFF YODR COMPUTER!"
70 GOSUB 210
190 END Vou must have this hers.
200 REM MESSAGE SUaKCUTINE *******
2X0 HOME Subroutine starts here,
220 PSIWT MESSAGES
230 FOR PAUSE = 1 TO STALL
240 NEXT PAUSE
250 RETUHIJ Subroutine ends here; program retums tt> pi
thcrt sent It hsrs wtlti GOSUB.
GOSUB means "Go to a subroutine." CA subrouftae is a routine wilhin a
program reached through a GOSUB instnjclion.) Like GOTO, GOSUU
makers the program go out of the normal sequence of line numbers to do
something. Lnlike GOTO, GOSUB rcliim,s to the point that it left; that's
wJiat RHTUliN does at the end of the subroutine. You don't have to keep
track of the line number to go back to; GOSUBNRETUTIN keeps track for
you.
END protects subroutines
SubrouilnL's usua^lly y.ppear at the end of a program (siib is Latin for under),
as in the examples in this session. You need io include an END instruction
between your main program and your subroutines.
To see why, take out the END instruction al line 190 and run ihc program.
(To take out a line, just type its line number and press I?eturn.)
END protects subroutjnes
J^peis t^seeTEm f '"™ "^^''^^ ^^"SUD. Your compmcr
Xnn^inn rr^ mstfucuon only when a COSUD sends it lo a
dne?n r t " ^^^^^^^'^^ ^ "^TURN by chance (as in Ihis case) it
,^«TaI '° '°* ^''■^ ^"'^ >™ » the
One way to make sure your subroutines are isolated from the main
Z'rthcn°ou!f r ''"^ ""'"^^^ >'™^
numbc;- " 'u'' ^" in^'^rtion right before that
,T program you've been working with the subroutine ^i-,rr<;
^ fn n'nr:,f ^ "™ - ^00:so tCr^ND^SnLtlaSn
Subroufines and organization
In thLs next example, the code appears in subroutines, not because the
program re-uses certain line segments often, but just because the nroLrn
.s easter to read and more organised that way. As you set better as a
fZ%lT"' f™^''-"-' '^"^ and do'more "i, gs As
.nore'Tm^^o^'anr'"' >"'"^ ^"'^
NEW
5 REM
10 REM Random NunLber Cenarator Program
12 REM i-hi. prograr. generates .r..y randoir, .ambers
1 lit, " ^^^^ — ^-i^-
wtM the r^ngg of numbers.
la REM
30 GOSUB 1010 : HEM Title page
3Q GOSUB 3110 : REM H^w many niimber. i „hat ranged
50 GOSUB 1210 , REM Gen.rata r^.dom number.
50 GOSUB 131D : HEM Go again?
60 IF ANS = ''Y- THEN 30 : Km Repeat if yes
"'O PR1*JT '" '
1D02 REM
1004 REM
Title Page
1006 REM
1010 HOME
1020 PRINT "Random Ntimher Generate r"
Programmfng With Style; Modular Programming
102O PBIHT "Handom Number Generator"
1030 PRIKT
ID^O PRIHT "Tills progran prints as many random numbers"
1050 PRIRT "as you want between tJ and any limit you choose."
lOGO PRIHT
1070 PRIHY
lOaO INPUT "Press Return to start: ";Start5
1090 RETURN
1102 REM * + *****#!**-*-**»--»***»*-«*-********
1104 REM How many numbera & w^^at limit:?
110& REM *****-****-****'*-****'''****-'***-^*
1110 HOME
1120 INPQT "How many numbers cio you wanr? "; RKUMS
1130 PRINT
1140 INPDT "What's the highest a number can be? LIMIT
1150 RETURN
1 202 REM *****************^************
1204 REM Generate Random Numbers
1 2 5 H EH *■»****••■•■*■"■»■■•-•**■• •*ii**it«*ii*n**
1210 FOR COUNl - 1 TO RNUHS
1220 NUn - RWO ( 1) ' LIMIT
1230 PRINT NUM
12flD NEXT COUNT
1250 PRINT
1260 RETORN
1302 REM
l^Dfl REM Go again?
130& REM
1310 INPUT "Do you want more random numbers? (Y/N) AN5
1320 RETURN
This program uses a lot of subroulines to make it easier to see what's
happening. Add to that all the REM instructions and the meaningful
variable names, and you have a program that's especially easy to
follow—both now, when youVe just wriucn it, and six months from now
when you might decide to change a few of the lines.
Multiple instructions on one [ine
YouVe probably already figured out that you can have more than one
instruction on a line if you put a colon CO between instructions. Examples
abound throughout the previous program. The program uses the colon
Multiple instructloris on ons line
only to add REM instruaions, but you can use the colon with a]]
instojctions. Be careful, though; someiimes the results can surprise you.
For example, if you start a line with a REM instruction, your computer
Ignores the whole line and not jusi the REM instruction:
20 REM This whole line ignored : GOSUB lOlD- GOSUB Ignored!
We'll leave it to your own experimentir^g to discover other such surprises.
Organizing your programs: one step at o time
Sometimes the scope of a program feels over^'hclminn. It seems loo
complex or Loo long or just beyond your skill level. Sometimes that's true
YOU really don't have the ability to write a program liiat will control the
nations budget Cand apparently, neither does anybody else). But you can
do more than you probably realize with the things youVe already lerirned
You can, for example, write a program to balance your checkbook.
The trick LS to break down the task into easily manasieable scgmenLs Think
tor a moment how you balance your checkbook when you do it by hand;
1. Get Che starting balance.
2. Add in the deposits.
a. Get the amount of a deposit,
b. Add that amount to the balance to produce a new balance.
c. Keep doing steps a and b until all deposits are added in.
3. Subtract amoums for checks.
a. Get the amount of a check.
b. Subtract that amount from the balance to produce a new balance.
c. Keep doing steps a and b unUl all checks are deducted.
4. Print the balance.
What you've jusl done is written out thealgoriihm (tliat is, the method to
solve the problem) for balancing a checkbook. Your next step is to write
modules or the steps in the algorithm; Ihen all you need to do is line up
the modules m the proper way. Program organisation is a matter of lining
up simple modules to work togelhcn
Programming With Style: Modular Programming
The great checkbook balancing program challenge
Use Ihe algorithm to write youf oivn checkbook balancing program. Add
a module that sets up a lUUe menu so you can choose what lo do first — add
the total of checks written, or add up deposits.
After you've written your own version, haive your computer print it out and
then check it against the one listed here. Treat this as an opportunity to
fjee how well you've under.stood what you've read in this tutorial. Take all
tlie lime you need; and remember to use REM lines liberally!
One version of a checkbook balancing program
This is just one version. If your version works, then it's just as good as this
one. This version is here jusi in case you got stuck.
The important thing about this version is thai it breaks the task down into
simple steps:
Module 1
5 REM
10 ftEK CHECKBOOK EftU^KCER
15 REM
20 HOKE
33 INPUT "Please type Starting balance: $ "; BALANCE
40 fRlPJT
50 PRIST Enter Deposits"
SO PRIHT -2. IritE Checks"
70 PRINT "3, End"
aO INPUT "CHOOSE SY NUMBER 1 NUMBER
90 IF HUMBEH = 1 THEN GOSUB 200
100 IF NUHBEEl = 2 THEN GOSUB 300
lia IF NUMBER = 3 THEN GOTO 17
120 IF NUMBER > 3 THEN GOio 40 Trops oLTt of rang& numbew.
130 PRINT "Your working balance is S BALANCE
140 PRINT
150 INPUT "Press Ret-uin to eontinue: "/STALLS Wclts fof usef to be ready.
ISC GOTO 40
170 PRINT
190 Pkim *'Your er.ding balance is S ".'BALANCE
190 END
The first module represents the "body" of the program. Subroutines
handle every other task. The next module handles deposits and adds them
to tlie balance.
The great checkbook bdaoclng program challenge
Module 2
^00 HEM
210 fiEM MAKE DEPOSITS
22Q REM
230 HOME
IZTlloZ' """^^'^ ■'^'^ -
260 INPUT "Amount o£ deaosit: S ■ dEP
BALANCE = BALANCE + D£p— ,,
230 MEXT X KsQps running total.
2 RETURN
Set rz.atL" "^^-^ «^ ^'^'^'"^ -
Modules
30D REH
310 REM WRITE CHECKS
320 REM
330 HOME
340 INPUT "HOW ma^y cheeky did ypu „rit^. mc
350 FOR X= 1 TO NC
360 INPUT "AinQUrtt of check- S rH-^rv
370 BALANCE = BALANCE - --r4 '
332 NEXT X ^ Xe&ps running toto]
390 RETURN
'^^^"X^^ T ~-
for you lo pracTicc on ^"^^ Program will be a good one
SummaiY and review
. i. Keep ,„s ,„ s^rszx" -T"-"''""''
Programming With Style: Modular Programml
Session 9
Formatting Screens
Generaling information on a computer is exciting and rewarding Rut Uie
mrormation itself. Ju^t as a neatly organized and primed page conveys
more .nformaUon than a bunch of scribbles on a scrap orp^ncr Jo too
cha^LW^fn"' t^'^^' ^^^^ ' '^P-t than a t^tgc of
charaacfs hurled ac the screen. • '"st ui
Clear screen presentation not only helps communicate .dcas- it helps vou
going to look on your screen, you rc also deciding what order your
program rnusl follow to gel the results you want Many pro~ers
S th:';^ol'rat " ^ ''^^^rbcgin to
This session teaches you *e instructions and some of the techniques vou
hShI- presentations. You'll learn about Sn/t?^
highl.ghung importani words, and creating menus. HTAR and vrAl lef '
you place text anj^vhcre on ihe .screen. LN-VERSE lets you drsplav
oFvI^^f '^'^ ^Sainst a light background the opposite
of vvhat u usttally ,s3; .VORMAL turns l.VVERSE off. You'll see how fo
Horizontal and vertical Tabs
On a typewriter, you place your tab stops across the page. On your
computer, you use HTAB to determine where the ne«ib slop be.
Type and i^jn this program:
NEW
20 HTAB 20
30 PSTNT "HEH^; IT IS"
'c ccn The HiAn' '^^'"^ '"^ ^P^-^^^^' V^ur
i^h^ UTAH h7 ^^^-^ ^^^^ text begin twenty column, lo the
across ™ recn OnThe'4n ' \" ^° ^^^^^^^^ ^"^-^cre
nIacS hp tZT^;.. Ihe 40<olumn screen, each increment over 40
places he text one more line down. For example. IITAD 120 places text
down ihree Hnes (120 / 40 - 3). places icxt
Formatting Screens
Type the following program and run il:
10 H0E4E
20 INPUT "HTAB valise <0-255) HZ
30 HTAB HZ
40 PBIMT "X"
30 PRiHT
60 RThB ?.0
70 INPUT tArtorher HTAB?[Y/N) " ;
80 IF AN$ = "Y" THEN 10 Lets us©r know pfOgrom's ovof,
90 PRINT "Thanits for trying ieib oyt [
IDO END Optional ending,
Usually you"!! use HTAB just to position your text horiTiontally, To make
vertical tabs, you'll use VTAB. \TAB works just like IITAB, but it can have
values only from 1 to 24.
To get a quick idea or how VTAB works, run this next little program:
10 HOKE
20 VTAB 10
2Q PRINT ^'ABOUT HERE"
Combining HTAB and VTAB, you can place text anywhere on the screen.
This next program lets you experiment with putting things on your screen
anyw'hcrc you want. Type and run it:
10 HOWE
20 INPUT "HTAB position (1 - -513) " ; BZ
25 IF HZ > 40 THEN PBIHT "Too high 1 ; GOTO 20
30 INPUT "^VTAB position {1 - 2^] VT
35 jF VT ? 24 THEN ?R1HT *'Too high!" : GOTO 30
30 HOME
50 VTA3 VT ; HTAB HZ ; PRINT "J£'»
60 VTAB 22 : HTAB 20
70 INPUT "Another? (Y/N| ; ANS
ao IF RNS <> "N" THEN 10
90 PRINT "flye, now."'
lOd END
In lines 50 and 60, the HTAB and VTAB instruaions are on the same line.
If you put HTAB and VTAB together like that, it's a little easier to organize
text placement.
Making stylish program menus is easy with HTAB and \TAB. This next
program uses a FOR\NEXT loop Co generate positions for text,
Horizontal and vertical tabs 71
NEW
10 HOME
30 FOR X-1 TO 6
^0 GOsuB lOQ ^ Can voufigua out What this does?
SD PRINT X; M^NUS
60 NEXT X
70 VTAB 30 : hTAB 5
BO INPUT "Choose by number: NUMBER
90 BSD
100 REM •**"«**---i.-i.-ir**. + M.*
110 flEM MENU SELECTIONS
RUM
130 IF X = 1 THEH MENUS = "Bring in the dog"
1-50 IF X - 2 THEW MENUS ^ "Put out the cat"
150 IF X = 3 THEN MENUS - "Foeci the gnfiila"
16Q IF J( = q THEN MENUS = -Wash the seal"
l-'O IF M = 3 THEN HEHUS - "Pat the c&mpLltet"
190 IF X = 6 TKEN MENtJS = "END"
190 RETUH_V
VTAB. But you can use thjs concept as a modd in your own programs.
<^ my menus wUh numt>e^P Good menu, let users make choices by typing just one
Which
animal do yo'^ wat-.t Infocmation about?
Pachyderrr
Pterodactyl
Ruffed Grouse
Serval
Programmnriis Machifieli.'^^yae
Exit Frogra:n
Please type your choice hete: |
This menu pracUcaily guarantees a typing error from all but the finest spellers
Your code w.ll have to include .11 kinds of special error protecUon to chec^ your
user, typing. Numbered menus eliminate the problem. ^
h'hlch ar.imai do you want information about?
1) Pachyderm
2) Pterodactyl
3) Huf£ed Grouse
4) Serval
5> Programrnorus Hachlnelinguae
61iEj;it Program
PlQ£LSe tvpe your chtjlce here il - 6ji: |
Formatting Screens
All your user has to do in this menu is type 2 number (and all youf code has to
check for is a numeric range), Numeric menus make things easiec for both the
user (who must type — and perhaps retype — choices) and for the programmer
(who must write the code).
Prompt placement
Good screen design demands ihac you pay atrention to how your INPUT
prompts appear. Programmers often need to ask users for a number of
inputs in a row — several street addresses, a number of prices, a series of
names.
T>pe and run this program. U g^t* ^ series of inputs while keeping things
neat. It uses HTAB and plus a new programnning trick:
10 GOSUB 20G Vou'll read about ttilsfater.
20 HOME
30 INPUT "liow many naaies to enter? NAMES
^0 HOME
50 HTA3 5 : VTAH 10
SO PRINT "Type in the names one at a ime . "
7 FOR X = 1 50 HAMES
30 HTAB 17 : VT^B 10 : PRINT SPACES
90 HTAE 17 : VTAB 10
100 INPUT "Name! "; NAS
110 NEXT X
120 END
200 REM ■■*********■**■***
2lQ REM SPACE MAKER
220 REM
22a FOR S = 1 TO 20 : REM SPACES 13 20 SPACES LONG
240 SPACES - SPACES 4. ■+
250 NEXT S
260 HETUHN
Again, this is just a sample. In a "real" program, you wouldn't just get names
and throw them away!
Tlie SpaccMaltCT: The subroutine at line 200 iniroduces a nifty
programming irick. You could have defined SPACES like this:
SPACES = " " 20 Spaces, Honest!
Hut that doesn't give you a very good idea of how many spaces are between
the quotation marks. Using a loop to build SPACES, as the subroutine at
line 200 does, lets you see exactly how big the "blank out" space is going to
be.
Prompt placamB
Of course, you arenl limited lo just using spaces. Instead of using spaces
l""' characters. Be creative-iust change whafs ^ '
between the quotatjon marks in line 240.
Getting noticed: INVERSE and NORMAL ~~
Your computer can print inverse charaaers on the screen The INVERSE
Tn S'^^RSF i^t'^r .^'S^^— d-k-on-light. Ail text afcr
Type and run this little program for a quick dEmonstration:
HEN
10 HOME
3 INVERSE
30' PRINT "THIS IS INVERSE"
40 NORMAL
50 PftlHT "THIS IS NORMAL"
If you take out line 40. all of the text will be inverse, Because inver,c text is
more useful ,n gett,ng attention than in presenting general displays ^ s a
m4sE' "8ht after youVe^mlshed with
invert o?om™'' T""™ ""^ ™m want, inforntation. use an
separates it from the menu choices:
10 HOME
20 TITLES = "MEHU"
3D PRIMT TITLED
10 FOR y = 1 TO 4
vi«y A] + __ FlguroWsoutyet?
60 PRINT "Chnice Hunter X
7a NEXT X
BO VTAB 20 : INVERSE W It O. h^fD
90 IWP[JT "CHOOSE OHEj "; CHOOSES
IDO HORMAL -= ■■
110 ...
...□ncitums \t offheie.
74 FofmaHing Screens
'^ INVF.RSE tS FOU UPPERCASE ONLY: INVERSE doesn't work well wilh lowercase
letters. For perverse technical reasons, lowercase Idlers sometimes gel changed
10 other ch3.racLers when ihey'rc displayed in inverse. Expcrimeni before you use
lowercase letters in your programs, just to be sure.
Experiment some with INVI£RSE. Try making an inverse line of spaces.
Put your name in inverse — in fact, use inverse Lcxl wilh asterisks to create a
movie marquee and see your name in lights!
A text- centering algorittim
As you saw in the lasl session, algorithms are formulas written to perform
different task.s. All of il:e tricks you've seen in these sessions arc actually
algorithms translated into computer code. As you've been experimenting
witti programs on your Apple, chances are you've developed some of your
own algorithms. Most of the subroutines you've used are algoriihms.
An algorithm for centering text is handy to have around, especially in a
session on screen formatting. To construct that algorithm, you'll need to
learn the LEN instruction. I,EN calculates the length of a string. Here's an
example:
NEW
10 ft? = "Apples Away!"
ZO PRINT LEN{ A^i ■-' ParertfhesBS are required (like T?ND),
RUN
12
Apples Away! has 12 characters (including the space).
When you center text, you put half the characters to the left of a line's
midpoint and half the characters to the right.
Now that you have the basic idea, figure out on your own how the
computer would see it. Write the code^ try it out, and then read the
solution in ihc next section.
One solution to the centering problenn
Once again, this is just one possible solution, if youfs is different and it
works, then yours i.s just as valid as this one.
Here's the algorithm:
1. Get the number of characters that fit on one line (the screen width);
that's cither -41} or 80 on your Apple — choose the one you're using,
2, Find the string length by using LEN.
A Isxt-centering olgorithm
4. Use HTAB to move to that position.
Expressed as computer code, it looks like this:
HTAB {WIDTH - LEN 1 LETTgRSS) ) /? An tj,«,
tJ^eae parentheses are necessory
MEM
10 HOME
2D INPUr "Enter any wqrd: hS
30 GOSUB 100
3 IMVERSE : VTflH 30'
50 INPUT "WOULD IfGU LIKE RNOTHER (i-/N> - anS
60 KORMAL : IF an5 = -y^- tHEK 10
■JO END
loo REM
110 ASM CENTER TEXT
120 REM
uo ™ r° " ' "™ ^^''^^'""^
150 PRIwr W5
IGO flETURN
Summary and review
expects you to do ncxi ^ u>ing lo say or what the program
FormanJng Screens
Session 10
Programming for People
BAsfcInd to fh/™'"' r^'j ^°"^P'='^d your introduaion to Applesoft
only smce ihe coming of personal computers. The ultimate EMii inTr
you to "humanize" your programs, to set them up in suTh a fay hat /ny
computer nov.ce can learn them quickly and use them easily ^ ^
A sordid history
Back in the old days (that is, before 1980 or so), programmers soent
almost none of their lime teaching their computes hTTo bchav^ with
humans. Programmers were primarily concerned with geuing
programs 10 work without being slopped too often by error me^aees-
because they themselves were usually the only people who useT^cfr
programs what they wrote didnt have to be "user'^^riendly " That was OK
^^^^ Most
^^^^-g^^'inS S'oup of sharing
CorrnT^hL T '° P^S^^-^' l*='y YOU will) it's
Progrommfng for People
People-program guidelines
Here are a Few principles you can follow when you write programs for
people, This list certainly doesn'i exhausi the possible ways you can make
your programs fit for human consumption, but it's enough to get you
started:
Give Clear Pf ompts. To make it easy for your users to see what your
program expects when it wants information, your program must
communicate exactly what 11 wants. Prompts should stand out, be worded
simply, and give the range of choices if there is a range.
Include Error Traps, People make mistakes. Your program should catch
errors as much as it can and give your users a chance to make things right.
Your program can easily check for the two most common problems: range
errors and typing mistakes. In a range error, your user types in something
that Is beyond the range cither of the computer or of the program:
50 . , ,
110 INPUT "lour choice - 0, 1, 2, or 3; CHOICE
120 If CHOICE < 4 THEN GOTO 170' ^ Bronchss If cholcs OK.
130 PRINT "Sorry - cfioice must be 0, 1, 2, or 3,"* Error Trap here-
1^0 PRIKT "Please make another choice."
150 PRINT
150 GOTO iio Goes back tor onother try.
170 = Comes here if OK,
In a typing mistake, your user types something he or she didn't mean, or
makes a simple spelling error:
90 . . ,
100 INPLTT "Name of pregram to erase; '• ; ERA5E5
110 PRIST
120 INVERSE
lao PRINT "MAHNTNGt IF YOU ERASE" Gfvbs □ Warning,
140 PRINT ERASES • Reprints entry,
150 PRINT "IT'S GONE FOREVER! "
ISO ?RINT
170 NORMAL
IBD IKPUT "WIPE OUT THE PROGSAM? (Y/N) KILLS
190 IF KILLS <> "i" THEN HOME: GOTO 100 Cancels If not Verified.
...
Leave an Exit Open. Don't forget to give users a way out of your program.
As wonderful as your program might be to use, people do hke to do other
things like eat, go to school, and take vacations. There are several ways you
can determine when your user has finished using your program.
PGopie-program guidelines
50 . . .
lt>a IKPUT "flow ruany ch^cfts did you wr=te- ■ CHFrv^
120 . . .
Or you can give an exit option after each entry:
90 . . ,
100 INPUT "ITc« r^uch 1. th. ne:<t ch^ck f^r? 5 ahOUnt
.10 BALANCE = BALANCE - AMOUNT
120 INPUT "Another check? (Y/N) ■ -'-ANS^
= THEN GO.,B 1000 . R^M Sh.w ..l.nce ..d .nd
'"^ir.^^^o^^^^^^ ^ - -i. option .fter
100 PRINT "1. EntBT more :,a:rBs"
110 PRINT "2. Change an entry
12ff PRINT "2. Print put all entries"
130 PBiKT "4. Leave the program"
1^0 VTAS 22 : HTAE 25
150 IHPUT "Your choice: " ; CHOICE
160 IF CflOICE - A THEN END
I"''0 . . .
To see the rules in action, type and run each of the foJlowins two
programs; the Hrst doesnt foHow the rules .nd the secordoe.
Ward Pro^irammfng (Yuch)
10 IHPUX A
2{] SUH=SUM + A
30 fRI^T SUM
^0 GOTO la
Programming for Peopfe
People Programming (Fantastic)
LQ SOKE
20 INPUT "ftrnOUnt CO add [0 to Stop)"; AHOiJMT : HEM Get amount,
30 IF AMOUNT = C THEN GOTO 13D I REM End if user's through.
\0 PRINT
50 PRINT "You aadeci "; ftHOUNTj right? [Y/N> ";
BQ INPUT YNS : REM Entry OK?
70 IF YNS them goto 30 : PLEIM If fior, gec It again.
90 SUM - SUM * AMOUNT ; REM Keep Running total...
50 PRINT
lOQ PRINT "Your tunning total is 3QH : REM ...and report it.
110 PRINT
L20 GOTO 20 : REM Get another number
L30 PRIKET
L40 PRINT "Final total: "; SUM : REM Print the final total.
Humanizing programs isn't easy
The second program requires more work than the first one. 11 Lakes more
planning, more typing, and more debugging to write a good interactive
program (tliat is, one that talks to people). It is also worth it. Real people
make mistakes; write programs with that in mind.
It gets easier
The more you learn about programming, the easier it gels. After you've
been programming for a while, you'll find that what once took you twenty
iines of programming you may do in only five lines. By experimenting,
playing, and trying new things with your Apple computer, your
programming ability will grow quicker than you can imagine.
Where do you go from tiere?
If you decide that programming's not for you, then there's no problem.
Vou don't have to know how an internal combustion engine works to drive
a car, and you don't have to know how to program to use a computer. Rut
if you've enjoyed going through this tutorial and you've decided that
programrnmg is fun and interesting, you can do lots of tilings to help
yourself learn more.
Where do you go from here?
Read Dooks on Applesoft Pfogramming: Hundreds of books have been
wrillcn on Applesoft, from tutorials lo advanced technical documents. Any
decent bookstore has at least a Tew Applesoft tides; the larger stores carry
dozens. The absolutely jndispensible resource is ihc Applesoft BASIC
Programmer's Reference Manual, published by Addison- Wesley (ISBN 0-
201-17722-6). Written by the cxperls at Apple Computer, Inc., this is J^ie
official Applesoft book. Your Apple Computer dealer or local bookstore
carries it or can order it for you.
Join an Apple Users Group; Made up of people at all levels of expertise.
Apple users groups arc a new computerist's best friend. As each member
learns something, he or she passes it on to the others. Most clubs have
special subgroups for beginners; virtually all of them have special interest
subgroups for learning Applesoft BASIC, as well as for other computer
languages. (Logo, Pascal, C, and Forth are the most popular ones.) Besides
being practical, these groups are a lot of fun.
❖ I'rce software/ One of itie best ways to leam how to write programs is lo look at
somebody else's. When you join an Apple users group, you'll have access to tons
of public domain software. And many public domain programs are written in
Applesoft.
Programming Classes; You can find programming classes in high schools,
universities, community colleges, computer stores, specially schools, and
users groups. Check with the instructor about the le%'el of the class before
you take it] if possible, talk to some graduates. Then you'll be sure that the
instruction is at the level you want.
Subscribe to Magazines About Apple Computers: There are dozens of
computer magazines, many specializing in Apple computers. See if you can
Hnd one thai deals exclusively with your model of Apple. Some Apple
magazines cover both Macintosh and Apple II family computers, while
others cover only one or the other. And some are aimed more at program
users than at program writers. Again, this is an area where a users group
can really help out. Not only can members recommend magazines that
have beginners' columns, but many clubs have libraries of back issues you
can use.
Do if!
The most important thing you can do to learn lo program is— to program.
W rite silly programs and serious programs, long and short programs,
programs that arc fancy, and programs that arc plain. Just do it! You'll
learn more from an hour of mistakes than from a week's listening in a
classroom. Code to your heart's content.
82 ProgrommJng for People
A parting word
This brief book has been a guided exploration through some oF the most
important concepts in elementary programming. You didn't learn all of
\hc instructions in Applesoft BASIC; there are far too many of them to
teach in one short manual. But what you learned here can serve you well if,
whenever you write a program, you remember that you're writing for other
people.
And keep on coding!
A parting word 83
Appendix A
A Summary of Applesoft
Instructions
This is a brief summary^ of aJl the instructions in the Applesoft BASIC language. 'Iliis
summary Is included for liiosc programmers already proficient in some other
ccmputer SanguagCj but new Lo Applesoft BASIC.
For a complete description of ihese instructions, see the Appiesojl BAS^C
rmgmmmer's Reference Manual (Addison -Wesley Publishing Company, Inc.).
AB$
ABS i-2,'l-f\
Yields tiie absolute value (value without regard to sign) of the argument. The
example yields 2.77.
ASC
A^C ("QUEST")'
Yields the ASCII code for the first character in the argumenL The example yields 81
(ASCII code for Q),
Assignment Instruction
LET A = 23.567
A$ = "iiUKBUG"
Assign.5 the value of Ihe expression foUowing ^ to the vartable preceding it. LET is
optional.
Appendix A
ATN
Yields ihe arc cangeni, in radians, of the argument. The example yields .720001187
(radians).
CALL
Execuies a machine-language subroutine at ihc speciRed decimal memory address.
"Ilie example issues a line feed.
CHR$
CHR$ (65)
Yields ihe character cofrcsponding to the ASCII code given as an argumcni. The
example yields Ihc leiEerA.
CLEAR
CL^ftR
Resets all variables and internal c.onErol information lo ihcir Iriidal stale. Program
Code is unaffected.
COL0R=
COLOR- 12
Sets the di.=;play color for plotting law-resolution graphics. The example sets the
dtaplay color lo green.
CO NT
CC3NT
liesumes program execution after ii has been halted by STOP, HND, CONTROL-C, or
(sometimes) CONTROL-RESET,
COS
cos {2)
Yields the cosine of the argument, which must be expressed in radians The example
yields -.416146836.
DATA
DATA JOHN SMITH, "CODE 32", 23.^5, -E
Creates a list of items for use by READ instructions. In the example, ihe first iiem is
the siring JOHN SMITH, the second is the string "code 22", the third is the real
njmber 23. '^5, and the fourth is iJie integer -6-
66 Appendix A
DEF FN
DEP FN CUBE (X) - K * X ■* K
Defines a new function Fur use in the program. The cKampIc defines a function that
yields the cube of its argument,
DEL
DHL 23, 56
Deletes a range of consecutive lines from the program. The example deletes lines 23
to 56^ inclusive,
DIM
DIM MARK (30,3), (50)
Defines and allocates space for one or more arrays. The example defines a two-
dimensional real array MARK, whose Hrst subscript varies from to 50 and whose
second varies from to 3, and a string array NAMES with one subscript that varies
from to 50.
DRAW
DRAW ■] i\T 50, IDO
DRAW ^
Draws a shape at a specified point on the high-res oluti on graphics screen from the
shape table currently in memory. The fir.?t example draws shape number ^,
[beginning in column 50, row 100, using the current color, scale, and rotation
settings; the second cKample draws shape 4 at the last point plotted by HPLOT,
DRAW, or yDI*A>X''.
END
END
Terminates the execution of (he program and returns control to the user. No message
is displayed.
EXP
EKV (2)
Yields the matliemaUcal eKponenilal of lEs argument (thai is, the conslant c —
2,7182810 — raised to the power specified by the argument). The example yields e
squared, or 7.3890561.
FLASH
FLASH
Causes all text displayed on Ihe screen with .subsequent PRINT statements to flash
between light-on-dark and dark-on-lighL May not work properly for lowercase
letters (and otJier d^iaracters with ASCII codes above 95) if the compulcr is runnini^ in
"aclive-BO' mode.
Appendix A
FN
FN CUBE (6}
Applies a designated function lo value of the argument expression. Assuming (he
definition for ihe function CUBE given under DEF FN. the example yields the value
216.
FOR
TOR J = 1 TO 10
FOR MARK = TO lOO STEP 5
FOR NUMBEH = 20 TO -20 STEP -2
Marks Lhe beginning of a loop, identifies the index variabEc, and gives the variable's
starling and ending values and Copuonalty) lhe amount by which it is to cliange (step)
on each p:3ss through the loop. The Rrst example begins a loop whose index variable
J takes on all values From 1 to 10, siepping by 1^ the .second begins a loop whose index
variable MARK takes on values from lo 100, stepping by 5; Lhe third begins a loop
whose index variable NUMBER takes on values fnDm 20 10 -20, stepping by -2_
PRE
>R£ (0!
Yields lhe amount of remaining memory, in bytes, available to the program. Also
forces "garbage collection" oF dead strings. The argument is ignored,, but must bs a
valid ApplesoFt expression,
GET
GET ANSWERS
Accepts a single characier from the keyboard witFiout displaying ii on the screen and
wiihout requiring that the Return key be pressed. Program execution is suspended
until the user pres.ses a key. In the example, the character typed is assigned to the
variable ANSWHRS,
GDSUQ
GOSUB 2 50
Kkcculcs a subroutine beginning at lhe designaKJd line number (250 in the example).
GOTO
GOTO 4 00'
Sends control uncondidonally lo the designated line number (400 in lhe example).
GR
GR
Converts the display lo 'SO rows of low- resolution graphics with four lines of text at the
bottom, The screen is cleared to dark, the cursor is moved lo the beginning of the
last line, and the low- resolution display color is set to black.
68 Appendix A
HCOL0R=
aCOLOR= 1
Sets the display color for ploUing high -resolution graphics. The example sets the
display color to green.
HGR
ConvcrLs the display to 160 rows of high-resolulion graphics with four lines for texL at
ihe bottom. The screen is cleared to black and page 1 of high-resolution graphics is
displayed. The contents of the text display, the location of the cursor, and the high-
re^oluiion display color are unaffected,
HGR2
Converts the display to hjll-scrcen (192 rows) high -resolution graphics with no text.
The screen is cleared to black and page 2 of high- resolution graphics is displayed.
The contents of the text display, the location of the cursor, and the high-resolution
display color are unaffected.
HIMEM:
HIMEM: 32767
Sets the address of the highest memory location available to the Applesoft program,
including ils variables. The example .sets the end of program and variable storage to
32767. Used to protect an area of memory for data, high -resolution graphics, or
machine-language code.
Him
HLIH 10, 20 AT 30
Draws a horlTiontal line in low-re.salution graphics, using the current low-resolution
dispby color. The example draws a line across row 30 from column 10 to column 20.
HOME
HOKE
Clears all lext from the text window and moves the cursor 10 \ht top-left comer of die
window,
HPLOT
HPLOT 75, 20
HPLOT 115 TO V9, B4 TO 110, 115
HPLOT TO 27 0, ID
PIols a point or line on ihe high-resolution graphics saeen in the current high-
resolution display color, llic first example plots a single point at column 75, row 20;
the second example draws lines from column ^8, row 115 to column 79,. row 8*1 to
Appendix
column no, row 115; the third draws a line lo column 270, row 10 from the last point
plotted with HPLOT, using the color of the last point plotted (not necessarily ihe
current display color).
HTAB
2 3
Positior^ the cursor to a specified column of the text display. Tht ejtample moves
the cursor lo coluitin 23.
IF.. .THEN
IF ftCE < IS THEN ft = 0:fl=l;C"2'
IF ANSWERS = "YES" THEN GOTO IDO
IF [J > MAX THEN GOTO 25
IF H > MAX THEN 25
IF N > KflX GOTO 25
Executes or skips one or more instrucUons, depending on the iruth of a. stated
condition. The firsi example sets A to 0, B to 1, and C to 2" if the value of AGE is less
than IS; the second branches to line 100 if the value of AKSWER^ is The slnng "YES"-,
t^ie last three all branch to line 25 if ihc value of N is greater than that of MAX. In all
esse.?, if tlie stated condition is fa.I.5e, execution continues with the nm program line.
\m
TNS 2
Specifics the source for subsequent inpuL The example causes subsequent input to be
read from the device at port 2.
INPUT
INPUT fl%
INPUT "TYPE AGE, THEN A COMMA, THEN NAME ",■ AGE^ NAMES
Reads a line of input from the current input device. Hie first example reads a value
into variable A%; the second displays a prompting message and then reads values
into variables AGE and NAMES.
m
INT (99. 6t
IHT (-273, 161
Yields the integer pari of the argument value. Hie examples yield 98 and -274,
respectively.
INVERSE
INVERSE
Causes all uppercase text displayed on the screen with subsequent PRINT instruaions
to appear in darlc-on-light instead of the usual light- on -dark. Has unpredictable
effects on lowercase text.
90 Appendix A
LEFTS
LEFTS ("APPLESOFT", 5)
Yields a specifiGd number of characters from the beginning of a string. The example
yields the string APPLK.
LEN
LSN ["NEVER A DULL MCMENT")
Yields the length of a string in characters. 'Ihc example yields 19.
LET
See "AssignmenL InslmcUon. "
U5T
LIST
LIST 150
LIST 200-300
LIST 20O, 300
Displays all or part of the program on the screen, or writes it to the current nuipui
device. 'Ihe first example lists the entire program; the second lists line 150 only; the
last two list lines 200 Eo 300, indiuive.
LOAD
LOAD DEMO
Reads a program into memory from a disk. The example reads a program from a
disk file named DKMO.
LOG
LOG t,2)
Yields the natural logarithm of the argument. The example yields .69'5'l47im,
LOMEM:
LOMEK;
Sets the address of the lowest memory location available to the program for variable
storage. The example sets the bieginniiig of variable storage to 24576.
MID$
MTD$ ("AtJ APPLE A DAY", 4, 5)
HID5 ("AN APPLE A DAY", A)
Yields a speofied number of characters beginning at a .specified position in a given
string. The first example yields the siring apple; the second yields She string apflf. a
DAY.
Appendix A
NEW
NEW
Clears the current program from memnry and resets variables and internal
conifol informaiion to thoir initial stales.
NEXT
WEKT
NEXT INDEX
NEXT J, 1
Marks, the end of a loop and cau.ses the loop to repeated Tor the next value of the
index variable, as specified in the corresponding FOR instruccJon. 'ITic first tixgmpic
ends the mo5i recently entered loop; the second ends the loop whose index variable
is I\l!)F.X-|, the ihird ends the pair of nested loops whose index variables are J and I.
NORMAL
Causes all text displayed on the screen with subsequent PRINT instructions to appear
in the usual light-on- dark; cancels the cfFecCs of INVERSE.
NOTRACE
NOTRACE
Stops the display of line numbers for each instruction executed; cancels liie effects of
TRACE.
ON...GOSUa
CM ID GOSUB 100, 200, 23, AQOb, 500
Chooses a subroutine to execute depending on the value of an expression. The
example transfers control to the subroutine beginning at line 100^ 200, 23, ^005, or
500, depending on whether the value of ID is 1, 2, 3. -1, or 5, if ID has none of these
values, execution continues with the next instruction,
ON. ..GOTO
ON ID GOTO 100, 200^ 23, ^D05, ^00
Chooses a line number lo branch to depending on the value of an expression. The
example transfers control to line lOO, 200. 23, ^005, or 5O0, depending on whether
the value of ID is 1, 2, 3. or 5i if ll^ has none of these value.5, execution continues
wiih the next instruction.
ON ERR GOTO
OKEH-< GOTO 5D0
Replaces Applesoft's normal error-handling mechanism witli a subroutine beginning
at a fipecified line number. The example establishes an error-handling subrouline
beginning ai line 500,
92 Appendix A
PDL
PDL (11
Reads ihc current dial setting on a designated hand conirol. The example reads Che
dial on hand control 1.
PEEK
PEEK (37)
Yields the cantcnLs of a specified location in rnemory. The example yields the
contents of location 37, which contains [he curreni vetLical posiuon of the text cursor
on the display screen.
PLOT
PLOT 10, 20
Plots a single block oT the current display color al a specified position on the low-
rcsolulion graphics screen. The example plots a block at column 10, row 20.
POKE
POKE -i63{32,
Stores a value in a specified location in memory. The example stores the value at
location ^19234 C6553<5 - 16302), causing the display to switch froni mixed gr^iplucs
and lexi to JflilUscreen graphics.
POP
POP
Removes the most recent return address from the control .■jtack, causing the next
i<K'Il.'R\ insuiiction to send control to [he instruction following the second most
rccenily execuled G03UB.
POS
PDS (0)
Yields the current horizontal position of the cursor on the text display. The
argument is ignored, but must be a valid Applesoft cxpre.ssion.
PRjf
PR# 1
Specifies the destination for subsequent outpuL The example causes subsequent
output to be sent to the device at port 1.
PRINT
PRINT
PRINT AS, "X X
Writes a line of output to the current output device. The first example writes a blank
line; the second writes Ihc value of variable A$, foilowed at the next available tab
position by the string "X ^ followed immediately by the value of variable X,
Appendix A 93
READ
he;ad ft, B%, c$
iieads values from DATA instruaions in ihc body or ihe program. The example
reads values into variables A, E%, and CS.
REM
RF,K THIS h REMARK
Includes remarks in ±Le body of a program for ihc benefit of a human reader.
RESTORE
RESTORE
Causes ihe next READ instruction cxccuied to begin reading al the firsl item of the
first DATA tnstruciion in the program.
RESUME
T<ES'jy.E
At ihc end of an error-handling routine Csec ONERR CjOTO), causes resumption of
[he program at the beginning of tlie instniction in which tlie error occurred.
RETURN
RETQRN
The last instruction m a subroutine returns control from a subroutine to ilie
instnjctiori following the GOSUB that called the subroutine.
RIGHTS
RIGHTS C'AFPLESOFT", 1)
Yields a specified number of characters from the end of a string. The example yickla
the string saw.
RND
RND (1)
Yields a random number between and 1. Zero and negative argument values yield
rcpcaiablc sequences of random numbers.
ROT=
ROT= 16
Sets the angular rotation for high-resolution shapc-.s to be drawn with DRAW or
XDRAW. The example causes the shape to be rotated 90 degrees clockwise.
94 Appendix A
SUN
RUM 500
RUN DEMO
Executes an Applesoft program, 'ETie firet example execures the program currenlly in
memory from the beginning, the second executes the program in memory, starting
at line 500; the third loads and executes a program from a disk file named DT;MO.
SAVE
SAVE DEKO
Writes the named Applesoft program currently in memory to a disk. The example
writes Che program to a disk file named DEMO-
SCALE=
5CflLE= 10
Sets the scale factor for high rcsoluUon shape.s to be drawn with DRAW orXDRAW.
■Jlie example causes the shape to be drawn ten limes bigger than the definition given
in the shape labie.
SCRN
SCRN (10, 2C)
Yields the code for the color currently displayed at a designated position m the low-
resoluiion graphics screen, The example yields the code for the color at column 10,
row 20.
SGN
SGN [-lUii
Yields a value of -1, 0, or +1, depending on ihe sign of the argument. The example
yields -1.
SIN
SIH (2)
Yields the sine of the argument, which must be expressed in radiins. The example
yields .909297427.
SPC
SFG (S)
Introduces a specified number of spaces into the line being wriuen by a PRINT
instruction. The example writes eight spaces.
SPEED-
SPEED = 5
Sets the rate at which texi chara.cters are to be sent to the display screen or other
input/output device. Ihe slowest rate is 0; the fastest is 255,
Appendix A 95
SQR
yields ihe positive square root of ihc argument; the example yields 1.41-121356.
STOP
STOP
Terminates the execution of Ihc program and returns conirol to the user. A message
is displayed identifying ihc program line in which the STOP instnjction appears.
STR$
5TR5 112.45)
YielcEs a string represeming the numeric value of the argumcnL The example yields
the siring "12.45".
TAB
TAB (23)
Positions ihc text cursor at a specified position on the output line during exeojlion of
a PRINT instruction. ITie example moves the cursor to column 23.
TAM
TAN 121
Yields the tangent of the argument, which must be expressed in radians. The
example yields -2.18503987,
TEXT
TEJCI
Converts the display to 24 lines of text, with the cursor positioned at the beginning of
the botlom line.
TRACE
TRftCE
Cau-ses llie line number of each instrucaon to be displayed on the screen as it is
executed,
USR
USR (3)
Executes a machine-language subroutine supplied by the user, passing it a specified
argument, The .subroutine is entered via a JMP (jump) instnictton stored at addresses
SOA through SOC hexadecimal. The example passe? the argufnent value 3-
96 Appendix A
VAL
VAL ("-3.7E4"1
^ ielcis [Pie numeric: value represented by the string supplied as an argumcnl. The
example yields -37000.
VUN
VUN 10, 20 AT 30
Draws a verLical line in low-icsoluiion graphics, using ihe currcnL low-resolution
display color. 'ITie yxampie draws a line down column 30 from row 10 to row 20.
VTAB
VTAB IS
Positions Ihc cursor to a specified row of the text display, 71ie example moves ihe
cursor to row 15
WAIT
WAIT 4 9337, 15
WftTT 19317, I5r 12
Suspends program execution until a spyctzificd bit pattern appears at a specified
memory location. Used to wait for a status signal from a peripheral device. The
second and (optional) third arguments are masks: the second specifies which bits of
the designated location are of interest, the iJiird specifics the values lo t>e tested for in
those bits. The first example suspends execution until a 1 bit appears in any of Ihc
four !ow-ordcr bit positions of location 495^7; the second waits for a 1 bit in position
Of 1 Or a bit in position 2 or 3-
XDRAW
XDRAW 1 AT 50, 100
KORAW 1
Draws a shaj-je from the shape table currently in memory at a specified poini on the
iiigh-rcsolution graphics ^screen. Each point in the shape is plotted using the
complement of the color currently displayed at thai point. Typically used to erase a
.^hajx; already drawn, The first example erases shape number 4, beginning in
column 50, row 100, asing the current scale and rotation settings; the .second
example erases shape 4 at the ]asl point plotted by IIPLOT, CKAW, or XDI^AW.
Appendix A
Appendix B
Reserved Words
Tabic B- 1 shows a list t>r Applesofi's reserved words. In most cases Lhcsc characLer
sequences cannot be used as, or embedded m, variable names.
'llie ampersand character (&} is reserved for Applesoft's internal use and for user-
supplied machine-language routines.
XPLOT 15 a, reserved word lhat does not concspond to a current Applesoft statemenl.
Some reserved words are recognized by Applesoft only in certain contexts:
COLOR, HCOLOK, HOT, SCALE, and SPEED ar^ interpreted as reserved words only
if the next nonspace character is an equal sign C=) This is of litUe benefit In the case
of COLOR and HCOLOR, as Ihc embedded reserved word OR prevents their use as
variable names anyway.
HlMliiVi artd LOMF.M arc interpreted as reserved word.5 only if the next ncnspace
character is a crylon G),
IN and PR are Interpreted as reserved words only if the next nonspace character is a
number sign (*^).
SCRN, SVC. and 'I'AB arc interpreted as reserved words only if the next nonspace
character is a lefL parenthesis, C
ATN is interpreted as a reserved word only if there is no space between the T and the
N. If a spate occurs between the T and the N, ihe reserved word AT is interpreted
instead of A'l'N.
Appendix B
TO is iatC^.jpialiA an ^ rr^i rvcd worr] unU'sS iL is preceded by an A and tbsi'C i;5 a hpiCC
,'3nd ihc O. In iJ-if.c caae, ih<^ reser^'ed word AT is i[ili:r])rL:l.i:d iiis-if-u-: nf"
']'0.
E'.ca ][' yn-Li doii'] (■^iiibrd rc;w.rvefJ wordy in t'cjr variable nvimes, they caa liacrLiil.iiTi:;.^
uj) Lincxpfiftedly and cay^e probJem^. For example, ttifj sLMl.i;rnc^n[
L^;" FGP = :.f5p"T o.^ luf::' lO' li
is iritcrprtMecf ^5
FC'l^ A = L9r TO RT.riFT ?0 ' H
3iinfd;.causos a syricaN: enoj-, To Jbrcc tltt: iTonr::;!. inii;r[;rci:jiio:i, iise parcn[hese&:
lubes' B-1 Applesoft Reserved Words
ATK
CAE. I.
CI IKS
CLHAR
CONT
COS
DA'E'A
DnF
DRh
DiM
DRAW
END
nxp
FLASH
m-
GET
tioyuiJ
GR
E KJ0[.01?.=
nCR
UGRZ
HIMRM;
llUN
ViOM H
iiPLOT
I-3TA]^
[!■
Lin-TS
LiiT
LIS'l'
LOAU
I. or,
LOMEM
M1D5
NEXT
NOTRACE
OK
E'DI.
PEEK
PLOT
E'OKH
?OP
PKINT
RHCALL
RETURN
lUGI-nt
KOT-
IlUN
SCALFl^
SCliNC
j^IILOAD
yTfip
^,TOP
TARC
TAN
TFXT
■■E'E3I'.N
TO
'L'KACE
VAL
VEIN
Vl'AB
■vVAI'E'
XDl'lAVi'
App<>ndix B
Glossary
address: A number used lo identify somcLhmg,
sudi as a location in the computer's memory,
algorithm: A Step-by-step procedure for solving a
problem or accomplishing a task.
Apple O; A family of persona] computers,
manufactured and sold by Apple Compuier, Tnc_;
generic name for all compuicrs in ihe series.
AppJesoft; An cxlended version of the BASIC
programming language used with iJic Apple n
family of computers and capable of processing
numbers in floaimg-point form. An interpreter
for creating and executing programs in Applesoft
is built Into the Apple II system in ROM,
arithmetic operalor: An operator, such as +, that
combines numeric values to produce a numeric
result; compare relational operator.
BASIC: Beginner? AU-purpose Symbolic
Itmmaion Code; a high-lt?vel programming
language designed to be easy to learn and use.
branchi To send program execution lo a line or
ia?tnicUon other than the next in sequence.
bug: An error in a program thai causes it not lo
work as intended,
catalog: A list of all fifes stored on a disk;
sometimes called a directory.
character: A letter, digit, punctuation mark, or
other written symbol used in printing or displaying
information in a form readable by humans.
code: (!) A number or symbol used to represent
some piece of information In a compact or easily
processed form. (2) The sLatementi or
instruclions making up a program,
command: A communication from the user to a
computer system (usually lyjxjd from the
keyboard) directing it to perfumi some immediate
action.
computer; An electronic device for performing
pn^defined (programmed) computations a: high
speed and with great accuracy.
computer system: A computer and its associated
hardware, firmware, and software.
concatenate: Literally, "to chain together"; to
combine two or more strings into a .single, longer
string containing all the characters in the original
strings.
conditional branch: A branch that depends on
llie truth of a condition or tl:e value of an
expression.
control variable: see index ^^iriable
counten A variable used lo keep track of passes
through a loop, Counters often have the form X -
X + L
crash: Vt^cn a program unexpectedly i:eases
operating, possibly damaging or destroying
information in the process.
cursor: A marker or symbol displayed on ihe
screen that marks where the user's next action will
take effect or where the next character typed from
the keyboard will appear,
debug: To locale and correct an error or the cause
of a problem or malfunction in a computer
sy.slem. 'I'ypically used to refer to software-related
problems.
Glossory loi
deferred execudon: The saving of an AppEcsori
program Hnc Tor excnzulion aL a lalcr lime as parC of
a complclc program; occurs when ihc line is lypcd
wiih a line number, Compare immediate
execution.
delay loup: A loop whose purpose is to slow down
the execution of a program.
define: To a.Si5.ign a value to a variable.
disk: An inrorniaUon-storagc medium consisting
of a flat, circular magnetic surface on which
information can be recorded in the form of small
magnetized spots, similarly to the way sounds are
recorded on tape.
disk drive A peripheral device that writes and
reads information on the surface of a magnciic
disk,
display; (1) Information exhibited visually,
especially on the screen of a video display device.
(2) To exhibit information visually, C3) A display
device.
display device? A device lhal exhibils information
visually, such as a lelevisJon receiver or video
monitor.
display sc-een: The glass or plastic panel on the
front of a display device, on which images arc
displayed,
edit; To change or modify; for example, to insert,
remove, replace, or move text in a document.
erroi" message: A message displayed or printed to
notify the user of an error or problem in the
execuiion of a program.
wcecutc: To perform or carry oul a specified
action or sequence of actions, such as those
defined by a program.
file: A collection of information stored as a
named unit on a peripheral storage medium such
as a disk.
filename: The name under which a file is stored
on a disk.
finmvare: Name applied to programs .stored in
read only memory.
format: (1) The farm in which information is
organized or presented. (2) To .specify or control
the format of informaEicn. (35 To prepare a blank
disk to receive information by dividing its surface
into tracks and sectors; also Initialise.
graphics: (1) Informalion preseaLcd in the form
of pictures or images. (2) Tlie display of piclurcs
or images on a computer's display screen.
Compare text.
hacker: An experienced programmer
hand corttrol; An optional peripheral device that
Can be conncclcd to the Apple ll's hand control
connector and has a rotating dial and a push
button; typically used to control game-playing
programs, but can be used in more serious
applications as well.
hang: For a program or system to "spin lis wheels"
indefinitely, performing no useful work.
hard copy: informalion primed on paper for
human use.
Inamediate execution: 'ITie execulion of an
Applesoft program line as soon as it is typed;
occurs when die line \s lypcd without a line
number Compare deferred execution.
index variable: A variable whose value clianges on
each pass through a loop; often called control
variable nr loop variable
Infinite loop: A section of a program that repeals
the same sequence of aclions indefinitely.
information: Facts, concepts, or insiruciions
represented in an organized form.
initialize: 0) To set to an initial state or value in
preparation for some computation. (2) To
prepare a blank disk to receive information by
dividing its surface into tracks and sectors; also
fur'mat
102 Glossary
input; (1) Information Iransferred into a
compUTSf from some external source, such as ihc
keyboard, a disk drive, or a modem. (2) The act
or process or iransferring such informaiion.
input variable: Variable whose value is sssigned
by the user via an INPUT instrucUon, as opposed,
to one whose value is assigned by the programmer
using an assignmem or similar instruction.
IfiKtruction: A unit of a program in a high-level
programming language that specifies an action for
the computer lo perform, typically corresponding
to several instructions of machine language;.
iniei'acilve; Operating by means of a dialog
between the computer system and a human user.
interactive prognumnlng: Generating programs
lhat operate by mcany of a dialog between the
computer system and a human user.
interface; The devices, mles, or conventions by
which one component of a system communicates
wi[h another,
inverse video; The display of lext on the
computer's display screen in the form of dark dots
on a light Cor other single phosphor color)
background, instead of the usual lighi dots on a
dark background.
kcybo^urd: "^Thc set of keys, similar to a typev/ritcr
keyboard, For typing information to the computer.
languaee See programming Luigii^.
line: See program line.
line number: A number that identifie-s a program
line in an Appie&ori program,
load: To transfer information from a peripheral
storage medium (such as a di,sk) into main
memory for use-, for example, to transfer a
program into memory Tor execution,
loop: A section of a program that is executed
repcasedly until some condition is met, such as an
index variable reaching a specified ending value.
loop varial>le See index vaiiahle.
low-resolution graphics: The display of graphics
on the Apple II's display screen as a sixteen-color
array of blocks, 40 columns wide and either 40 or
rows high,
memory: A component of a computer system Lhat
can store information for later retrieval-, see main
memory, random-access memory, read-only
memory.
menu; A list of choices presented by a program,
usually on the display screen, from whiuh the user
t:an select.
mode: CD Any of several ways a computer
interprets information. (2) A state of a computer
or system that determines its behavior.
nested loop: A loop contained within the body of
another loop and executed repeatedly during each
pass through the containing loop.
nested subroutine call; A call to a subroutine from
within the body of another subroutine.
numeric variable! sec ■rairijilile
operator; A symbol or sequence of characters,
such as + or AND, specifying an operation lo be
performed on one or more values Cthe operands)
to produce a result.
output: (1} Information transferred from a
computer to some external destination, such as
the display screen, a disk drive, a printer, or a
modem, (2) 'nie act or process of trarasferring
.Such information.
pass: A single execution of a loop.
precedence; 'Hie order in which operators are
applied in evaluating an expression.
printer: A peripheral device that writes
information on paper En a form easily readable by
humans.
program: (I) A set of instaictions tlmt describes
actions for a computer to perform in order to
accomplish some task, conforming to [he rules
and conventions of a p&riicular programming
GIossotY 103
language. In Applesoft, a sequence of program
lines, eacli with a different line number. (Z) To
write a program.
program Kne; The ba.?ic unit of an Applesoft
progfam, consisting of one or more instructions
separated by colons G).
programmer; 'llie human author of a program;
one who writes programs,
programming; The acdvlty of writing programs,
programming langLiagC! A set of mlcs or
conventions for writing program.?.
prompt: (1) To remind Or signal the user that
some action is expected, typically by displaying a
disdnctive symbol, a reminder message, or s.
menu of choices on (he display screen. (Z) An
instruction or reminder message that appears on
the display .screen.
prompt character: CI) A text character displayed
on the screen to prompt the user for some action.
Often also identifies the program or component of
the system that is doing the promplingi for
example, the prompt character j is used by the
Applesoft BASIC 3nLcrprcter, Abo called
prompting chamaer. CZ) Someone who is alway.s
on time.
prompt message; A message displayed on Uie
-strreen vo prompt the user for some acilon_ Also
called prompltng messit^s.
RAM: See random-access memory.
random-access memory: Memory whose
contents can be both read and written-, often
called read-write memory, The contents of an
individual location in random-access memory
can be referred to in an arbitrary or random
order. The information contained in Ihis lype of
memory is erased when ihc computer's power is
turned off, and is permanendy lost unless it has
been saved on a more permanent storage
medium, such as a disk. Compare read-only
memory.
read: To transfer inFormation into die computer's
memory from a source external to the computer
(such as a disk drive or modem) or into tlie
computer's proces.50r from a source external to
the processor (such as the keyboard or main
memory).
read-only memory: Merrtory whose contents can
ht read but not wrilten- used for storing firmware.
Information i.s written into read-only memory
once, during mangfaclurc; it then remains there
permanently, even when the computer's power is
turned off, and can never be erased or changed.
Com^parc random-access memory.
read T^Tite memor)': Sec random-access memory.
relaUonal operator; An operator, such a^ >, [\\a\.
compares numeric values to produce a logical
result; compare arfthmetic operator.
reserved word; A word or sequence of characlcrs
reserved by a programming language for some
special use, and therefore unavailable as a variable
name in a program.
ROM: See read-only memory.
routine; A pari of a program that accomplishes
some task subordinate to tlie overall task of the
program.
run: 0) lb execute a program. C2) To load a
program into main memory from a peripheral
storage medium, such as a disk, and execute it.
save: To transfer information from main memory
to a pcnphcral storage medium for later use,
screen; Sec display screen.
starting value: The value assigned to the index
variable on the first pass through a loop.
stepvainc! The amount by which the index
variable changes on each pass through a loop.
stepwise refinement: A technique of program
development in which broad sections of the
program are bid out first, then elaborated step by
step until a complete program is obtained.
104 Glossary
string: An iiem of information consisting of a
sequence of text characters.
string variabiB see variable.
subroutine: A pan of a program thai Can be
executed on request from any point in the
program, and ihat relurns cpntrol to the point of
ihe request on completion.
syntax: 'iTie rules governing the structure of
slsnements or instructions in a programming
language
system: A coordinated callcction of interrelated
and interacting parts organised, to perform some
funcUon or achieve some purpose-
text: (1) Infoimation presented in the form of
characters readable by humans, (2) The display of
characters on the Apple \Vs display screen,
Compare graphics,
user: The person operating or conLrollIng a
computer system.
user interface: The rules and convcntiorTS by
which a computer system communicates with the
fxirson operating it.
value; An. item of information that can be stored
in a variable, such as a number or a string.
varialtle: (1) A location in the computer's
memory' where a value can be stored. (Z) '["he
symbol used in a program to represent such a.
location.
wraparound; The automatic continuation of text
from the end of one line to tlte beginning of the
next, as on the display screen or a printer,
write: 'lo uansfer information from the computer
to a destination external lo the computer (such as a
disk dri\^e. printer, or modem} or from the
camputer's processor to a destination external to
the processor (such as main memory).
Index
Cast of Characters
^ (dollar sign) 22
& (ampersand) 99
^ Cplus sJgn} e-H, 22
- CsubliacLion opcraloO ^j-U
(piyriod) 30
• (mukiplicalion operator) S-11
/ (division operator) fi-11
i (colon? 55 -66
; C-icififcolon} 13, 39
Oess Lhan operator? 39
(not greater than operator) 39
(noL equal to operator) 39
= Ceqml sign) 13, 59
^ Cgrealer lhan operator) 39
^= (not less lhan opt:ra.tor} 39
1 <quc:slion mark) 1 8, 1 ?-20, 40
1 (righi bracket prompO ix, x
A
in.5lruct.ion 85
adding lines 20
addition operator {+? 8-11
precedence and 10-11
alyariLhms 66
ampersand 99
animation
srilhmcLic 8-11
arithmetic operatora S-9
arrow keys 4
ASC instruction
assignment instructions 18, S5
AT instruction 48^9, 99, lOO
ATN instruction B5, 99
branchint> ice GOTO instruction;
IF.,.TI-iEn insiruaton
bugs 4-5
iffe also debugging; errors
C
CAU. instruction S6
catalog 29
CA'Y command 29. 31
rcnLcring icxt 75-76
checkbook balancing
program 66-63
CHRS instruction 86
clearing screen 20-21
CLEAR instruction 86
code See programming; programs
colon G) 65-66
COLOR= Instruction -IT, 86, 99
color graphics 44-51
color monitor 44
comments See REM instruction
Computer languages v|l
concatenation 22
conditional branching
See IP.. .THEN instruction
CONT instruction 86
Conlrol-C 37
Control-Reset x
controlled loops 54-58
COS instruction 86
counters 48
D
IJA'I'A instruction 86
debugging 4-5, 14, 23-25
by printing 32-33
See also errors
deferred execution 24-25
DEF FN instruction 86
delay loops 57-58
DELETE command 32
DctcLc key 4
DEL instruction 87
DIM instruction 87
disk drives 28
starling up without x
disks 2S
display. 'lO'Column 11, 70
division operator 00 8—11
precedence and 10^1 1
dollar sign (J) 22
drawing lines 4S— 50
DRAW instruction 87
E
editing programs 'i-S, 20
END instruction 39. 63-64, 87
equal sign (=) 12
equal to operator 39
error mcMagca 3-4, 24-25
REESTZR 23
RETURN WtTHOL'l GOSUS 64
SYNTAX ERROR 5-4
TYPE kish;stch H
errors 4-5
trappmg 41, 79
See also debugging
execution 3, 24-25
exit aptions, dc&ignmg 79-80
EXP instruction 67
index
F
nies Sgb programs
['l,ASH insi ruction B7
FN inslruclion S7
formatiing screens 70-76
FOR\N'EX:r instruaion 5'i-5S, 88
STEP insifuciion and 56-57
^0-column display 11
ITTAB instruction and 70
fracUons 9
rUE instruction 88
S
Girr instruction 88
Gosi:nMiE"imN
inslnjction 88
GOTO in.nructEOn 36-37, 63, 83
1F...THKN insiruction and 4C
CR inSLTUclion 44-^5, 88
graphics
FORXNE-XT instruaion and 55-57
low-rtsoiution 44-51
KND fnslruction and 50-51
variables and 47—58
graphics mode 44—45
greater than C>) opojator 39
H
hardcopy 5ee prir^ling
IICOLOR= inatmaion 83,9?;
1 IGU (nsifuction S9
I IGR2 tnsiruaion S9
IIJMBM: instruction 89,99
ULIN instruction 4S->i9, 89
HOME instruction 2Q-2\, Q9
ItPLOT inMruaion 89
H't'AU inslnjction 70-73, 90
I. J, K
IF,..TilEN instmcUon 37--'U, 5'J. 9t)
CO'J'O instruction and 4[>
immcdiait; txecgtio'n 2^-2"^
IN** instruction 90, 99
incrementing counters 48
infinite loops 37
INPirr inMm^tion lS-20, 73, 90
string variables and 23
input variable 18
in struct ionCs)
sssignmcnt 13, 85
multiple 65-66
summary of 05-97
See also speci^c instruction
intcractivt programmiiTig 18, 7S-4J]
INT instruction 90
INVCRSn instruction 74-75, 90
L
languages vii
l.K|-rS instruction 91
I^ft-Arrow key i
U-;K instruciion 75-76,91
less than <<^ operator 39
LET instruction 91
line number 2, 3, 20
tines
adJing 20
drawing 48-50
runover 1 !
L3ST command 21-23, 91
LOAD coiiimand 29, 51-32, 91
LOG inslnjction 91
LOMEM; instfuaion 91. 99
loops 36-37
controlled 54-58
delay 57-58
lowercase 3
INVERSE instruction and 75
low-re5olutiDii graphics 4^-51
M
memory iiTe R/VM; ROM
menus 71-73
MID$ insiruaion 91
modes 44
modular programming 62-63
monitors 44
monochrome monitor 44
multiple instructions 65-66
Imtllipli^^^io^ operator (*) E^Il
precedence and 10-tl
naming
numeric variables 13, 23
programs 29^30
string variables Z3
NEW command 2-3= 92
NEXT inslmclion 5ee FOK^NEK:!'
instruction
NORMAL instruction 74-75, 92
nnt cqua! to Co> opcralof 39
not greater than C*^~} operator 39
not It^ss than operator 39
NOTRACE instruction 92
numbers, as text 22
numeric Variables 11-14
naming 13, 23
o
ON 20
{5MKliH GOTO in$tmaion 9^
ON,,.GOSLfB instnjcUon 92
ON, .GOTO instmcUon 92
operators
arlthmtlic 8-9
rclatianaJ 38-^1
order of precedence 9-11
parentheses and 10-11
oigimizing programs 66
Oil iiTrstruction 99
103 index
parentheses
precedence and 10-11
rdservi:d words and 99-100
RND Ensinjiction and 50
PAUSH program 62-63
POL instnicUon 93
PEEK inslrucLion 93
period Q, in filenames 30
PLOT ijisLruciion 45-^6. 48-49, 93
plus sign (+), siring variables
and 22
POKE insmjction 93
POP instruction 95
POS inslrucdon 93
PR* command 33, 93, 99
precedence 9-11
parenlheses and lO-Tl
priming 32-33
PRINT inslmclion 2-A. M, 19, 93
ariilimctic and 8-11
qucsUon m«trk O fnd AO
program line 2. 3, 20
proyrainming viii-Lx
interactive 18, 78-81
modular 62-68
resources 8]S2
profjrams viii-ix
editing 4-5, 20
menus and 71-73
namin^j 29-30
organizing 66
printing 32-33
saving 29-30, 38
"user- friendly" See tntcraclivc
programming
prompt character (J) Lx, x
prompts 19-20. 73
designing 79
inverse 74-75
public domain software 82
Q
question mark C?) 18. 19-20
PlilNT instruaion and -SO
quotation nnarki 8
llAM Crandom-access memory) 2H
range errors 79
liKAD instruction 94
_st:.ENTER message 23
relational operaiors 38-41
REM inslruclion 41, 9'i
reserved words 14, 20, 99-100
I^1:"5T0RB instruction 9^
RESUME inslrucLion 94
RETURN insLruclLon
See GOSUa\RETUEN
instruction
Return kty 2-5
RETURN WITHOUT GOSQB
message 64
RIGHTS instruction 94
BiBht-ATTow key -1
IfXD inslnic'ion 9-1
graphics ^nd 50—51
HOM (read-only Ttemory^ 28
ROT- instruction 94, 99
RUN commsnd 2-3, 95
runover lines 11
S
SAVE command 29-30, 95
SCALE- insLruciion 95, 99
screen(s)
clearing 20-21
formatting 70-76
low -resolution 45-^6
SCRNC instriuclion 95, 99
semicolon 19. 39
SG^' instruction 95
SIN instDJClion 95
software, public domain 82
Space bar 4
SpaceMaker 73-74
spaces 9
SPCX insEnidion 95, 99
SPEI;D= instruction 95^ 99
SQR instrticlion 96
starting up ix-x
STEP instruction 5S-57
STOP instruction 96
STRS instruction 96
string variables 22-23
subfoud nes 62—68
subtraction operator C-) 8-11
precedence and 10-11
SYNTAX EHROK message 3-4
T
TAEC instruction 96, 99
labs See HTAB insiruction^
TABC instruction; VTAB
in*trt]ction
TAN insipjction 96
television set 44
text 22-23
centering 75-76
TEXT instruction 46. 96
text mode 46
THEN instructEon JeeIF...THEN
instruction
TO instruclion IQQ
TR.\CE instruction 96
trapping errors 41,79
TypE MISMATCH message 14
typing mistakes 3, 79
U
uppercase 3
imTRSE inslruction and 75
"user-friendly'" programs
Sen interactive programming
users groups 82
USR ir^struqtion 96
Index 109
V
VAL insLmction 97
variables \^-\A
FQR\NEXT inslruction and 55
graphics and -17-48
input 13
naming 13, 23
numeric 1 1-H
suing 22^23
VI.IN" instruction A&-A9, 97
VTAB insunction 70-73, 97
w
WAIT instruction 97
X, Y, Z
XDIiAW instruction 97
XPLOT inslruaion 99
110 Index
VJ-S
E ^
8-
5"
OD
Ik
I
5-
3
I
n
c
I
I
□
c
u
CL
I
4
- c_
■ era
II "
? &
5
I
3
3
I
1^
il E
/J ja
— r-
=■ =;
3 d
c
3
i
S
■6,
5
IT
a, 5'
II '
1
.3
3-
1
£ — r
C
C
n
5*
n =. =r t £ ;
— IT
M
-• u z
".5 3
I' f
3 =
li
-1
I
II
3^
ST
3-
ET
rj'
>
■n
-a
SI =
>
3-
c
r.
1^
3
C_
C
>^
c
3-
c
w
ft
I
— 7!
3
a'
I i
•3
c
5
M
fV
1.1
" 3
^1
1%
Li
n
u —
5'
3 ^
—
oar
H ^ 2
3 ~ ^
S. 3-
n ri
"3_
I- ^ ^
Jf - ^ 3-
:l ^ P *
- ■ -3
3. "5
= If
= "EL.::
3 " =
n E
1
il
it
K ^ = fr
: ^
^7. J.
^ H i
■ill
* 3 "
r ^
— ^
> 3"
5-
a B
S H B
B H B B a
B
B B B B
4 1^ J. 4-
B
B B B B a
B B B B B B
B B B B
B B B
B
DDDDDDDD
DIDDDDDD
I D D D D D D D D
|DD
f n
1 n n n n []
I I
n I I
I I
3"
to
O
s